fakerphp / faker Goto Github PK
View Code? Open in Web Editor NEWThis project forked from fzaninotto/faker
Faker is a PHP library that generates fake data for you
Home Page: https://fakerphp.github.io
License: Other
This project forked from fzaninotto/faker
Faker is a PHP library that generates fake data for you
Home Page: https://fakerphp.github.io
License: Other
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.
Version | |
---|---|
PHP | 7.4 |
fakerphp/faker |
1.9 |
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
In de_AT/Address.php there's a TODO comment to implement more strict postal code values:
Faker/src/Faker/Provider/de_AT/Address.php
Lines 16 to 17 in 6027e18
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
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)?
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
Version | |
---|---|
PHP | 7.4.12 |
fakerphp/faker |
1.14.1 |
$faker->valid()->e164PhoneNumber
Phone number to be valid
Phone number is invalid
@fzaninotto can you please do that for us?
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.
This is a standalone repository. Therefore, anyone who contributes to it will not get any GitHub credit, like https://github.com/username Activity.
Esp since the original is abandoned, simply delete this repo, create a blank one, and do git push --tags origin master
.
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.
fakerphp/faker v1.13.0 / php 8.0.1
$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);
}
Calculator/Inn.php
verifies the Russian tax identification number (INN number), Calculator/TCNo.php
the Turkish Identity Number - sounds like stuff that should be in localized providers?
Should we move the Calculator/Inn.php
methods to ru_RU/Company.php
, mark them deprecated in Inn
and call the new methods in Company.php
for BC? Similarly with TCNo
/tr_TR/Person.php
.
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:
Faker/src/Faker/Provider/at_AT/Payment.php
Lines 35 to 38 in 9f1d7e8
Faker/src/Faker/Provider/de_AT/Payment.php
Lines 15 to 18 in 9f1d7e8
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
would have to be moved to de_AT/Payment.php and at_AT/Payment.php be deleted (which would obviously be a breaking change).Because phars bin subdeps without all the other hacks that were merged after.
Any ideas to add markdown to faker?
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:
Something seems up with the national insurance stuff. Either we have flakey generation, or a flakey test?
Originally posted by @GrahamCampbell in #96 (comment)
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
Version | |
---|---|
PHP | 8.0.3 |
fakerphp/faker |
v1.13.0 |
$this->faker->personalIdentityNumber();
This should produce a valid personal identity number with birth number > 000.
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.
When running the PHP-Stan a warning is displayed:
191 Call to an undefined method Faker\Generator::company().
Version | |
---|---|
PHP | 7.4.16 |
Symfony | 5.2.6 |
fakerphp/faker |
1.14.1 |
$faker = Factory::create();
$company = $faker->company();
No Error.
191 Call to an undefined method Faker\Generator::company().
$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
{
// ....
}
Hello,
The package support language Code using languageCode
but there is no language name like English
, Spanish
, Arabic
...
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?
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.
Version | |
---|---|
PHP | 7.4.11 |
fakerphp/faker |
v1.11.0 |
User = User::query()->create([
'google_id' => $this->faker->unique()->numerify('#####################'),
'foo' => $this->faker->dateTimeThisYear,
]);
// Insert `foo` into db column `timestamp` on `users` table.
Insert to work
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.
Using e164PhoneNumber()
, an invalid number is created for en_US. The generated phone numbers that start with 0 or 1, are invalid.
Version | |
---|---|
PHP | 8.0 |
fakerphp/faker |
1.14.1 |
$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
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!
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:
Faker/test/Faker/Provider/BaseTest.php
Lines 319 to 322 in 7dea0d7
Faker/test/Faker/Provider/BaseTest.php
Line 340 in 7dea0d7
Version | |
---|---|
PHP | 7.4 |
fakerphp/faker |
1.12.0 |
<?php
$regex = '/[.]/';
$result = \Faker\Provider\Base::regexify($regex);
var_dump(preg_match($regex, $result));
int(1); // result should match the regex
int(0); // result does not match the regex
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
Version | |
---|---|
PHP | 7.4.14 |
fakerphp/faker |
1.14.1 |
$this->faker->catchPhrase
'Some catch phrase'
InvalidArgumentException
Unknown formatter "catchPhrase"
If you call the uuid() method on the Generator, then everything works because the Uuid provider exists and it has this method. But this method is not described in the Generator
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.
Romania's phonenumber combination gives random validation on generated numbers.
Version | |
---|---|
PHP | 7.4.18 |
fakerphp/faker |
1.14.1 |
Preparing a patch with correct combinations.
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
.
Version | |
---|---|
PHP | 8.0.3 |
fakerphp/faker |
1.14.1 |
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.
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??
1.14.1
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?)
I think Factory
class name is too generic. Please consider renaming the class to e.q FakerFactory
.
Every time when I run the randomNumber() method, it returns a 0 value. I use it in Laravel 8.34.0 if it matters.
Version | |
---|---|
PHP | 8.0.1 |
fakerphp/faker |
1.14.0 |
$faker = new \Faker\Generator();
$number = $faker->randomNumber();
echo $number; //0
every time a new random number
0
Updating composer dependencies currently leads to:
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
It'd be great if this package was suggested instead.
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.
Version | |
---|---|
PHP | 7.4 |
fakerphp/faker |
1.9 |
Hello,
In Faker there is support for uuids but only version 3. Would you consider adding support for V4 as well ?
There was a PR in the old repo fzaninotto#1536
https://github.com/symfony/polyfill-uuid/blob/main/Uuid.php could be relevant here and could also be used to generate the other versions
I can make a PR if you're up for the change
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.
Version | |
---|---|
PHP | 8.0.0 |
fakerphp/faker |
1.13.0 |
echo Faker\Factory::create('en_US')->phoneNumber; // 884.863.4355 - invalid
Faker should generate valid phone numbers.
Faker generates invalid phone numbers.
The PR that should fix this issue is still open: https://github.com/fzaninotto/Faker/pull/1838/files
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.
Version | |
---|---|
PHP | 7.4.15 |
fakerphp/faker |
1.13.0 |
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.
php: ^7.2.5
Version | |
---|---|
PHP | 7.2.34 |
fakerphp/faker |
1.14.1 |
As Faker is now an organisation, I think it makes sense that faker get's its very own logo 🥇
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.
Version | |
---|---|
fakerphp/faker |
1.y.z |
See #309 on how to fix the bug
String quotes are inconsistent (sometimes double, sometimes single). How about we enable single_quote
in StyleCI to fix this?
Originally posted by @krsriq in #108 (comment)
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.
Version | |
---|---|
PHP | ALL |
fakerphp/faker |
main |
Tests are now seeded with 1
to assure test result consistency but that opens another potential issue:
Faker/test/Faker/Provider/PaymentTest.php
Lines 36 to 39 in 0d72e9f
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.
While testing random data generation in a reproducible way is difficult, we should make sure our tests are working properly.
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.
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.
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.
It would be really great if Faker could offer a version
generator, able to return a valid version string, acc. to Semantic Versioning.
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.
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:
Version | |
---|---|
PHP | N/A |
fakerphp/faker |
dev-main |
<?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));
}
}
$ php -f test.php | column -t
Locale Max Mean Count
$ 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
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.
Version | |
---|---|
PHP | 7.4.9 |
fakerphp/faker |
1.13.0 |
app(Faker\Generator::class)->optional(1)->firstName;
John (Or any other first name)
null
$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�
Version | |
---|---|
PHP | 8 |
fakerphp/faker |
1.14.1 |
$this->faker->randomHtml(2,3)
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.
Faker/test/Faker/Provider/uk_UA/PersonTest.php
Lines 11 to 18 in 907b307
other tests just check that a non-empty result is returned, e.g.
Faker/test/Faker/Provider/bn_BD/PersonTest.php
Lines 18 to 22 in 907b307
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?
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().
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.
Version | |
---|---|
PHP | 7.4.7 |
fakerphp/faker |
1.9.1 |
<?php
$faker = Faker\Factory::create();
echo $faker->image("public/storage/avatars", 400, 400, "people");
the path of the stored image file (i.e. public/storage/avatars/13b73edae8443990be1aa8f1a483bc27.jpg)
0
How about enabling StyleCI for the test directory to make the test classes more consistent?
As mentioned in #90 and #80 (comment) @GrahamCampbell?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.