Giter Club home page Giter Club logo

faker's People

Contributors

aanfarhan avatar ankitpokhrel avatar applestump avatar bazo avatar bessl avatar dependabot[bot] avatar dynom avatar foobarquaxx avatar fzaninotto avatar grahamcampbell avatar igorsantos07 avatar ionbazan avatar jremes-foss avatar krsriq avatar localheinz avatar nineinchnick avatar nyholm avatar oittaa avatar okj579 avatar pimjansen avatar pomaxa avatar ppelgrims avatar ronanguilloux avatar softius avatar tharoldd avatar timwolla avatar tzhuan avatar vlakoff avatar yerlenzhubangaliyev avatar zachflower avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

faker's Issues

curl 'via.placeholder.com/500' -> cloudflare 503 error

Summary

Hi there is problem with Image placeholders, which is not exactly the fault of the library but due to that $faker->image returns 0, it happens because when you curl via.placeholder.com/500 it will return 503 error. If you open link in the browser first time you get cloudflare ddos protection. Is there a way around it??

Versions

1.14.1

Use seed() in tests?

I'd like to increase the Provider test coverage a bit. To do so I checked out the existing tests and saw different approaches taken:

some tests use seed() to ensure a certain result is returned, e.g.

public function testFirstNameMaleReturns()
{
$faker = new Generator();
$faker->addProvider(new Person($faker));
$faker->seed(1);
$this->assertEquals('Максим', $faker->firstNameMale());
}

other tests just check that a non-empty result is returned, e.g.

public function testIfFirstNameMaleCanReturnData()
{
$firstNameMale = $this->faker->firstNameMale();
$this->assertNotEmpty($firstNameMale);
}

Another approach would be to test that we're dealing with a valid string (in the case of firstNameMale()) or via regex a valid pattern.

Is there another solution I have overlooked/any other ideas? Which solution do you prefer?

Invalid US PhoneNumber

Summary

Porting this issue because it still matters to me... The current phone number generators have the possibility of producing results considered invalid by Google Firebase and Stripe, among others. This is due mostly to random extensions on Faker\Provider\en_US\PhoneNumber which either cause the number to be too long or invalidate it because of the "x" character.

Please consider breaking phone numbers out (like streetName, streetSuffix, and streetAddress) and/or supporting a PhoneNumberSimple generator.

fzaninotto#1909

Versions

Version
PHP 7.4
fakerphp/faker 1.9

Lazyload locales (Customize load different locale files)

Lazyload(or require/install whatever) locales (Customize load different locale files).
A good advice is composer subpackage...

For example:
Init default english_US faker:

composer require fakerphp/faker

Install Chinese_CN locale:

composer require fakerphp/zh_CN

Optional weight not working as intended

Summary

In the documentation, it says that passing 1 to the optional modifier will always return the provider. However, when I pass 1, it's using the new percentage system, so there is actually only a 1% chance of returning the provider. Also, using the percentage based system, we will no longer be able to pass boolean values to the optional modifier.

Versions

Version
PHP 7.4.9
fakerphp/faker 1.13.0

Self-enclosed code snippet for reproduction

app(Faker\Generator::class)->optional(1)->firstName;

Expected output

John (Or any other first name)

Actual output

null

Markdown

Any ideas to add markdown to faker?

randomHtml error

Summary

$this->faker->randomHtml(2,3)
Error:

PHP Deprecated:  Since fakerphp/faker 1.14: Accessing property "word" is deprecated, use "word()" instead. in /Users/tina/Sites/jetstream/vendor/symfony/deprecation-contracts/function.php on line 25�

Versions

Version
PHP 8
fakerphp/faker 1.14.1

Self-enclosed code snippet for reproduction

$this->faker->randomHtml(2,3)

Generates invalid US phone numbers

Summary

Faker is generating random invalid US phone numbers.
If you validate phone numbers in your app - you can't use Faker because of its randomness - sometimes it generates a valid phone number and tests pass, and sometimes it doesn't.

Versions

Version
PHP 8.0.0
fakerphp/faker 1.13.0

Self-enclosed code snippet for reproduction

echo Faker\Factory::create('en_US')->phoneNumber; // 884.863.4355 - invalid

Expected output

Faker should generate valid phone numbers.

Actual output

Faker generates invalid phone numbers.

The PR that should fix this issue is still open: https://github.com/fzaninotto/Faker/pull/1838/files

Stricter postcodes for AT?

In de_AT/Address.php there's a TODO comment to implement more strict postal code values:

// As per https://en.wikipedia.org/wiki/List_of_postal_codes_in_Austria (@todo implement more strict postal code values according to wikipedia)
protected static $postcode = [

I looked through the other address providers - some have a list of (presumably) all available postcodes (such as en_GB), some use numerify/regex to generate postcodes (such as en_AU), others use completely random numbers.

Does it make sense to have a list of all valid postal codes hard coded, as the comment suggests? Especially since a generated address would then still be likely invalid, because it's a random combination of a postal code and a city

"{{streetAddress}}\n{{postcode}} {{city}}",

So one possible solution would be to just remove that TODO comment and live with invalid postal codes, or to hard code all available postal codes (and still live with invalid postal code/city combinations).
A more advanced solution would be to build a data structure that has a hierarchy of state-postcode-city, so only valid combinations are possible - but that would probably be overkill (and a solution I couldn't find in any other providers)?

Feature: Add Language name

Hello,

The package support language Code using languageCode but there is no language name like English, Spanish, Arabic ...

Faker image generator returns 0

Summary

Faker image generator doesn't store any image and return 0 (false) as a result.
Curl extension is enabled on php.ini and allow_url_fopen is set to On.

Versions

Version
PHP 7.4.7
fakerphp/faker 1.9.1

Self-enclosed code snippet for reproduction

<?php

$faker = Faker\Factory::create();

echo $faker->image("public/storage/avatars", 400, 400, "people");

Expected output

the path of the stored image file (i.e. public/storage/avatars/13b73edae8443990be1aa8f1a483bc27.jpg)

Actual output

0

Feature request: minimum character count for realText

I recently wrote a simple loop to ensure realText() would provide a minimum character count. It would be nice if this could be added as a parameter to the method itself instead. I'm more than happy to PR this in, and will likely do so over the weekend.

Suggestion: Fixing/caching data to create consistent datasets

Currently every call to a faker data generator function generates fresh random data. What I'd love to see is an option to switch faker into a cached mode where calls to the same function will generate data once and then always return the same data until caching is switched off.
Since Faker internally calls generator functions to create more complex data this would allow to create consistent datasets. To elaborate:
Lets say I want to create a set for a person, currently what I would get is something like this:

With caching this would give me something like this:

Feature Request: "version" generator

It would be really great if Faker could offer a version generator, able to return a valid version string, acc. to Semantic Versioning.

Example:

echo $faker->version; // 2.11.3

This should be a relative small addition that could perhaps become part of current (or version 2.x) of Faker.

Nb: I'm sorry if this feature request is misplaced. I was sadly not able to find any valid information about where such should be created / placed.

Extension-free US phone numbers

Summary

Porting this issue because it still matters to me... The current phone number generators have the possibility of producing results considered invalid by Google Firebase and Stripe, among others. This is due mostly to random extensions on Faker\Provider\en_US\PhoneNumber which either cause the number to be too long or invalidate it because of the "x" character.

Please consider breaking phone numbers out (like streetName, streetSuffix, and streetAddress) and/or supporting a PhoneNumberSimple generator.

fzaninotto#1909

Versions

Version
PHP 7.4
fakerphp/faker 1.9

Company name is not very random in some locales

Summary

The company name (company()) returns a small number of distinct results in some locales. The script below measures the distribution, the locales that are really problematic are probably these:

  • bn_BD
  • en_GB
  • en_SG
  • hy_AM
  • ja_JP
  • mn_MN
  • th_TH

Versions

Version
PHP N/A
fakerphp/faker dev-main

Self-enclosed code snippet for reproduction

<?php

use Composer\InstalledVersions;

require 'vendor/autoload.php';

$locales = array_map(fn($path) => basename($path), glob(InstalledVersions::getInstallPath('fakerphp/faker').'/src/Faker/Provider/*_*/'));

printf("%s\t%s\t%s\t%s\n", 'Locale', 'Max', 'Mean', 'Count');

foreach ($locales as $locale) {
    $faker = \Faker\Factory::create($locale);
    $names = [];

    for ($i = 0; $i < 10000; $i++) {
        $names[$faker->company()] = ($names[$faker->company()] ?? 0) + 1;
    }

    if (max($names) > 10) {
        printf("%s\t%u\t%.0f\t%u\n", $locale, max($names), round(array_sum($names) / count($names), 0), count($names));
    }
}

Expected output

$ php -f test.php    | column -t
Locale  Max   Mean  Count

Actual output

$ php -f test.php    | column -t
Locale  Max   Mean  Count
ar_JO   13    4     2853
ar_SA   18    5     1918
bn_BD   1127  1126  9
de_AT   11    3     3680
de_CH   17    3     3079
de_DE   12    2     4928
el_CY   13    2     4839
el_GR   25    13    812
en_GB   109   94    99
en_SG   1237  1233  8
en_ZA   29    19    493
fr_BE   14    4     2447
fr_CA   15    3     3395
fr_CH   15    3     3466
fr_FR   14    2     4537
hr_HR   13    4     2471
hu_HU   35    14    693
hy_AM   108   95    110
it_CH   15    3     3107
ja_JP   109   95    102
lt_LT   19    5     1943
me_ME   66    54    180
mn_MN   1159  1153  8
nl_BE   15    4     2445
pl_PL   12    3     3345
th_TH   117   106   92
uk_UA   38    23    450
zh_CN   47    32    324
zh_TW   11    3     3720

PHP-Stan - Call to an undefined method.

Summary

When running the PHP-Stan a warning is displayed:

191 Call to an undefined method Faker\Generator::company().

Versions

Version
PHP 7.4.16
Symfony 5.2.6
fakerphp/faker 1.14.1

Code snippet for reproduction

$faker = Factory::create();
$company = $faker->company();

Expected output

No Error.

Actual output

191 Call to an undefined method Faker\Generator::company().

Work around

$faker = Factory::create();
$company = $faker->company;

But, in this case, a warning is logged:

Accessing property "company" is deprecated, use "company()" instead. 

This will be nice to update the Generator to propose the accessing method instead:

...
@method string company()
@method string email()
...
class Generator
{
    // ....
}

Invalid E.164 phone numbers

Summary

E.164 phone numbers, generated by package seems to be invalid.

For example, i've got generated +6734232851178 and according to google/libphonenumber it is invalid, here is an example: https://libphonenumber.appspot.com/phonenumberparser?number=%2B6734232851178

Versions

Version
PHP 7.4.12
fakerphp/faker 1.14.1

Self-enclosed code snippet for reproduction

$faker->valid()->e164PhoneNumber

Expected output

Phone number to be valid

Actual output

Phone number is invalid

Feature: Active URL

Summary

Some frameworks like Laravel support to validate active urls. It uses dns_get_record to check if A or AAAA dns record exists.

It would be nice if faker had a function that provides only active urls.
Maybe freeEmailDomain could be used for a start.

Versions

Version
PHP 7.4.15
fakerphp/faker 1.13.0

Release latest stuff

Hello! First of all, thanks so much for the great package and for the great work!

I wanted to ask if it would be possible to make a release, I'm after some recent additions, more specifically #255

Thanks!

Unknown formatter "catchPhrase"

Summary

After updating to 1.14.1 ->catchPhrase now throws the following error:

Unknown formatter "catchPhrase"

After brief investigations I believe it has been caused by the following commit affecting Laravel app's with faker_locale set to en_GB

7e6c6b0#diff-c65f89c9fc1f2402100a21efa32250b826e08a21c73aa1c84a6d023523132795

Versions

Version
PHP 7.4.14
fakerphp/faker 1.14.1

Self-enclosed code snippet for reproduction

$this->faker->catchPhrase

Expected output

'Some catch phrase'

Actual output

InvalidArgumentException 

Unknown formatter "catchPhrase"

Move VAT from Company to Payment?

Most localized providers that have a vat method have it in the Payment class (e.g. es_ES or fr_FR) - except for two that have it in Company: nl_NL and zh_TW.

Should we move the vat method of these two outliers to their respective Payment classes and call these methods from Company for BC? Should we then also mark them as deprecated in Payment?

Birth numbers of '000' is not valid for Swedish personal identity number

Summary

Birth numbers of '000' is not valid for Swedish personal identity numbers. This causes problems in our unit tests.

The birth number is the first 3 numbers of the last 4, marked with X here 19900101-XXXN

This is probably the most used package when you work with Swedish personal identity numbers and this does not validate the numbers produced: https://github.com/personnummer/php
It specifically fails on this regex: https://github.com/personnummer/php/blob/master/src/Personnummer.php#L124

Versions

Version
PHP 8.0.3
fakerphp/faker v1.13.0

Self-enclosed code snippet for reproduction

$this->faker->personalIdentityNumber();

Expected output

This should produce a valid personal identity number with birth number > 000.

Actual output

Once per 1000 runs on average, this will result in a personal identity number with 000 as birth number, for example: 19640825-0006. This is not valid.

Austrian provider in de_AT as well as in at_AT

Is there a reason that Austria can be found in Providers/de_AT and in Providers/at_AT?

at_AT is rather empty except for a Payment.php file - in which obvious code duplication is happening:

public static function bankAccountNumber($prefix = '', $countryCode = 'AT', $length = null)
{
return static::iban($countryCode, $prefix, $length);
}

public static function bankAccountNumber($prefix = '', $countryCode = 'AT', $length = null)
{
return static::iban($countryCode, $prefix, $length);
}

As I understand it the first part of a locale is the language, the second part the country code - at isn't a language, but a country with de/German as the official language.

To fix this the method

public static function vat($spacedNationalPrefix = true)
would have to be moved to de_AT/Payment.php and at_AT/Payment.php be deleted (which would obviously be a breaking change).

e164PhoneNumber() generates invalid US Phone Numbers

Summary

Using e164PhoneNumber(), an invalid number is created for en_US. The generated phone numbers that start with 0 or 1, are invalid.

Versions

Version
PHP 8.0
fakerphp/faker 1.14.1

Self-enclosed code snippet for reproduction

 $faker = FakerFactory::create();

dump($faker->e164PhoneNumber());

Example invalid number that was generated: +16200858074

Tested using giggsey/libphonenumber-for-php library locally as well as the online version
https://giggsey.com/libphonenumber/index.php?phonenumber=%2B16200858074&country=US //Starting with 0
https://giggsey.com/libphonenumber/index.php?phonenumber=%2B16201858074&country=US //Starting with 1

both isValidNumber() and isValidNumberForRegion() fail

BC Check Failing

Please don't merge PRs with failing BC break. If we want to allow the change, the bc break checker yml config needs to be updated to allow the specific case.

Inconsistent results with many instances

Summary

I have been using faker within Orchestral Testbench. My code generates many instances of faker (one for each of my tests), and each instance is seeded deterministically and generates a large number of variables. My tests started failing, especially when changing between versions of php (7.3, 8.0.1). In summary, I expect faker to behave deterministically - but it doesn't. I've included example code below. On my system, it consistently fails on iteration #5961. I'm not sure if this is a memory issue? I ended up solving it by creating a static instance of faker, and reseeding it. However, I thought I'd create this issue in case anyone else has run into this.

Versions

fakerphp/faker v1.13.0 / php 8.0.1

Self-enclosed code snippet for reproduction

$expected = '234,299,984,500,634,563,254,832,504,421,778,973,198,709,235,740,836,263,88,848,320,319,41,186,3,336,490,891,813,798,384,30,274,118,292,728,918,541,283,872,543,414,856,779,373,422,674,814,442,826,434,105,618,283,513,65,651,941,403,240,806,11,522,384,86,332,319,445,90,670,697,593,890,76,829,853,46,556,626,882,548,272,184,864,799,229,147,165,643,310,248,598,296,132,884,984,679,467,165,876,605,296,93,872,174,161,845,659,384,402,945,436,988,647,540,409,179,149,746,171,597,606,99,366,462,372,412,2,39,449,357,127,79,918,305,761,665,337,774,215,956,803,576,612,680,778,361,114,346,421,43,232,880,441,764,471,878,351,417,706,397,821,492,863,598,392,262,283,702,506,25,967,303,670,242,995,438,331,566,617,475,748,705,865,934,616,15,867,340,957,501,508,18,106,556,663,318,169,483,465,416,92,854,855,68,659,533,397,782,884,719,544,586,721,37,866,351,856,563,894,696,491,491,977,324,402,159,790,50,803,660,844,108,943,826,499,886,248,637,327,218,2,753,708,898,987,250,238,527,734,405,963,857,816,819,309,358,210,48,477,755,52,454,696,227,97,622,648,72,345,72,65,567,220,534,137,990,250,18,650,573,428,792,835,443,966,878,817,584,193,709,808,148,373,575,744,309,186,104,414,440,773,829,351,498,765,819,835,90,785,800,34,431,261,589,139,198,127,567,371,709,322,37,934,974,559,552,673,745,77,438,250,385,355,168,983,839,70,405,794,783,577,154,581,603,234,224,483,616,448,21,131,751,32,827,843,547,980,491,980,484,799,845,96,822,217,14,686,849,676,252,586,457,574,579,0,116,255,339,751,94,612,288,373,77,843,206,238,574,165,710,248,656,596,199,927,351,581,93,96,814,109,213,710,393,574,140,295,384,178,747,74,167,278,737,448,508,385,353,361,782,445,896,960,38,247,317,465,136,883,310,816,973,648,946,690,184,279,69,728,748,652,914,354,458,263,130,543,194,746,403,306,973,906,147,175,274,592,709,409,647,466,210,608,151,434,466,79,559,8,122,366,378,308,576,595,485,966,105,953,697,794,396,267,794,20,590,411,185,541,162,280,434,111,945,155,989,457,229,25';

for ($i = 0; $i < 10000; $i++) {
     $faker = Faker::create();
     $faker->seed(10);
     $result = [];
            
     for ($j = 0; $j < 500; $j++)
          $result[] = $faker->numberBetween(0, 1000);

     $result = implode(',', $result);
     if ($expected != $result) die('FAIL: ' . $i);
}

dateTimeThisYear generating invalid datetimes

Summary

I'm not sure this is fixable, but I occasionally get test failures because the random dateTime it generates it like during an hour that doesn't exist in the year due to daylight savings.

Versions

Version
PHP 7.4.11
fakerphp/faker v1.11.0

Self-enclosed code snippet for reproduction

User = User::query()->create([
    'google_id' => $this->faker->unique()->numerify('#####################'),
    'foo' => $this->faker->dateTimeThisYear,
]);

// Insert `foo` into db column `timestamp` on `users` table.

Expected output

Insert to work

Actual output

  SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2020-03-08 02:24:45' for column `users`.`foo` at row 1 (SQL: insert into `users` (`google_id`, `foo`, `updated_at`, `created_at`) values (253337100756074437708, 2020-03-08 02:24:45, 2020-11-21 11:46:14, 2020-11-21 11:46:14))
  • 2020-03-08 02:24:45 is between the 2-3am hour when daylight savings occur, so that hour effectively is removed.

I'm not even sure if this is Faker's responsibility or if this is mine with setting time zones, configuring database (MariaDB 10.2) or something else. I'd figured I throw a bug in first to be sure.

Doctrine\Common\Persistence vs Doctrine\Persistence

Summary

Older versions of Doctrine use Doctrine\Common\Persistence while newer versions moved to Doctrine\Persistence as the namespace for classes like ObjectManager

In the original repository, there was already an open discussion (and MR) for this: fzaninotto#2059
fzaninotto#2055

I'm not 100% sure how long we should support both versions of Doctrine or how this backwards compatibility should be tackled. (Perhaps a major version upgrade? Or 2 separate Populators?)

randomNumber return 0 every time

Summary

Every time when I run the randomNumber() method, it returns a 0 value. I use it in Laravel 8.34.0 if it matters.

Versions

Version
PHP 8.0.1
fakerphp/faker 1.14.0

Self-enclosed code snippet for reproduction

$faker = new \Faker\Generator();
$number = $faker->randomNumber();
echo $number; //0

Expected output

every time a new random number

Actual output

0

Add a logo

As Faker is now an organisation, I think it makes sense that faker get's its very own logo 🥇

Regexify dot issue

Summary

regexify does not handle [.] properly. It should treat it as literal ., not "any character" when it is in square brackets. This can be reproduced with test:

public function testRegexifyBasicFeatures($input, $output, $message)
{
self::assertEquals($output, BaseProvider::regexify($input), $message);
}

using following data set:
['[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}', 'complex regex']
without seeding the generator (to assure randomness).

Versions

Version
PHP 7.4
fakerphp/faker 1.12.0

Self-enclosed code snippet for reproduction

<?php
$regex = '/[.]/';
$result = \Faker\Provider\Base::regexify($regex);
var_dump(preg_match($regex, $result));

Expected output

int(1); // result should match the regex

Actual output

int(0); // result does not match the regex

Replace imageUrl with the previous one or picsum

I observed that we've changed our imageUrl from the Image provider, though it makes sence to provide a real image, what is the reason we replaced lorempixel into using placeholder.com?

Isn't it supposed to be make it as textImageUrl() instead?
TBH, text image isn't useful to foresee real life designs with expected image result.

<?php

namespace App\Faker;

use Faker\Provider\Image;

/**
 * Depends on image generation from https://picsum.photos
 */
class Picsum extends Image
{
    /**
     * {@InheritDoc}
     */
    public static function picsumUrl(
        $width = 640,
        $height = 480,
        $seed = null, // Tend to be the $category, but since picsum is randomized, we use it to cache instead
        $randomize = true,
        $word = null,
        $gray = false
    ) {
        $size     = "/$width/$height";
        $grayPath = $gray ? '?grayscale=1' : '';
        $seedPath = $seed !== null ? "/seed/$seed" : '';

        return strtr('https://picsum.photos{seed}{size}{gray}', [
            '{seed}' => $seedPath,
            '{size}' => $size,
            '{gray}' => $grayPath,
        ]);
    }
}

The above code is what I used now to override the Image provider, though this supposed to be the imageUrl() and replace the one we have to be textImageUrl().

`Base::unique` contains null while type says it does not

Summary

Base::unique property is not initialized in constructor and its type does not allow null value.

Though, the null value is there so the type is wrong and it's a bug.

Versions

Version
fakerphp/faker 1.y.z

Self-enclosed code snippet for reproduction

See #309 on how to fix the bug

Extract language into own packages

Summary

As mentioned by François Zaninotto in his blog post about shutting down Faker, he wrotes that Faker is just too large because it includes data for 70+ languages. The goal would be to extract the language data into own repositories that can be included depending on the languages that you need for your tests/seeds.

Car faker

Summary

I really need a generator of Types and Brands of cars.
I can't use "pelmered/fake-car" because it uses the new version of PHP ^ 7.3 || ^ 8.0
or the archived "fzaninotto/faker" package for my version of php.
Other unpopular packages are not updated. I need a package that will be regularly updated like this.

Versions

php: ^7.2.5

Version
PHP 7.2.34
fakerphp/faker 1.14.1

Test randomness

Summary

This topic was brought up by @krsriq in #82 and partially addressed in #90. This issue is to discuss possible solutions to make sure our tests are properly checking the library behavior.

Versions

Version
PHP ALL
fakerphp/faker main

Self-enclosed code snippet for reproduction

Tests are now seeded with 1 to assure test result consistency but that opens another potential issue:

public function testCreditCardTypeReturnsValidVendorName()
{
self::assertContains($this->faker->creditCardType, ['Visa', 'Visa Retired', 'MasterCard', 'American Express', 'Discover Card']);
}

In this code, $this->faker->creditCardType will always return MasterCard because generator is seeded with 1 before each test method execution so removing the last element in array will still make the test pass every time.

Possible solutions

While testing random data generation in a reproducible way is difficult, we should make sure our tests are working properly.

Retry tests

I have tried experimenting with PHPUnit --repeat 100 flag to repeat the test several times but setUp (and therefore seed(1)) is called before each repeat too.

Mark tests that require seeding

Another approach would be to introduce a custom @seed <int> annotation for test methods or classes that explicitly require seeding before test to get specific results:
https://github.com/FakerPHP/Faker/blob/main/test/Faker/Provider/ja_JP/InternetTest.php and https://github.com/FakerPHP/Faker/blob/main/test/Faker/Provider/uk_UA/PersonTest.php

This approach together with --repeat 100 flag in one of our test matrix should allow us to make sure all the tests are actually making sure that generated data is always correct.

Other notes

  • How to make sure that each element is returned at least once after N repetitions?

Doctrine\Common\Persistence\ObjectManager used in Faker\ORM\Doctrine\Populator was moved in another namespace in Doctrine 2.8.x

Summary

The class Doctrine\Common\Persistence\ObjectManager was moved to Doctrine\Persistence\ObjectManager in Doctrine 2.8.x. It is used in Faker\ORM\Doctrine\Populator.

Versions

Version
PHP 8.0.3
fakerphp/faker 1.14.1

Expected

The code bridging Faker and Doctrine should probably be extracted to a separate package fakerphp/faker-doctrine in order to allow proper dependencies management using Composer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.