DummyGenerator is dummy/fake data generator for PHP. It's a fork of Faker heavily rewritten at core, but overall is same easy to use. In example:
$generator = new DummyGenerator(DefinitionContainerBuilder::all());
echo $generator->firstName();
Faker died for our because of being hard to maintain - more on that here and Faker 2.0 seems to be dead because of "death by committee" kind of stuff.
I needed simple dummy data generator for PHP 8.3 and with modern architecture in mind, so DummyGenerator came to life.
- required PHP >= 8.3
- PHPStan level 8 friendly
- PHPUnit tests for core and extensions (yep, some just check for not empty, but hey, it's random data)
- all
mt_rand
/array_rand
replaced with\Random\Randomizer
- no static methods, only one magic method (
__call()
in generator) - interfaces and dependency injection for everything (all core implementations can be replaced with different ones)
- language providers removed from core (that makes it ~9.8Mb smaller)
- removed database providers (core is only for dummy data generation)
- removed
HmlLorem
,Uuid
(you can use any uuid generator, Symfony, Ramsey...) - removed
File::filePath()
since it was interacting with system, not only generating dummy data
There are two Randomizer implementations, default Randomizer
and if someone need it there is XoshiroRandomizer
that allows to use seed
for testing purposes (check BiasedTest
).
Providers are gone, but here are sample providers en_US
,en_GB
and pl_PL
to show how to make them / convert from old Faker.
composer require johnykvsky/dummygenerator --dev
Everybody like quick start - it's here, you're welcome.
How to use them, Quick Start is not enough - just check this
Once you're done with previous readings you can read more about available interfaces. It's important read, because you will get to know how to overwrite stuff with your custom implementation (not just by "extend class").
There is script\ExtensionsDocs.php
that can be used to generate list of available extensions and their methods (look at generate-spec.php
)
Since --repeat
is still missing in PHPUnit here is Linux shell script for running tests multiple times.
- ...