This package implements all you need for effective dummy data generation:
- doctrine/data-fixtures allows you to populate your dev database or provide data for tests.
- fzaninotto/Faker generates fake data.
- nelmio/alice manages all that in config. This package adds .neon support.
Via Composer:
$ composer require zenify/doctrine-fixtures
Register extensions in config.neon (includes Kdyby/Doctrine configuration):
extensions:
- Kdyby\Annotations\DI\AnnotationsExtension
- Kdyby\Events\DI\EventsExtension
- Kdyby\Console\DI\ConsoleExtension
doctrine: Kdyby\Doctrine\DI\OrmExtension
fixtures: Zenify\DoctrineFixtures\DI\FixturesExtension
doctrine:
host: localhost
user: root
password:
dbname: database
# default values
fixtures:
enabled: FALSE # turns on by default in CLI
faker:
providers: [] # here you can add list of custom providers
alice:
seed: 1
locale: "cs_CZ"
loaders:
neon: Zenify\DoctrineFixtures\Alice\Loader\Neon
This extension loads fixtures from *.neon
files, turns them into entities and inserts them to database.
To understand fixture files, just check nelmio/alice.
Short example: this will create 100 products with generated name:
Zenify\DoctrineFixtures\Tests\Entities\Product:
"product{1..100}":
__construct: ["<shortName()>"]
When you have your fixtures files ready, you have 2 options to load them:
Run in console in your project's root:
# show all commands
$ php www/index.php
# run fixture command
$ php www/index.php doctrine:fixtures:load
# get info about fixture command
$ php www/index.php doctrine:fixtures:load -h
$fixturesLoader = new Zenify\DoctrineFixtures\DataFixtures\Loader;
$fixturesLoader->loadFromDirectory(__DIR__ . '/fixtures');
$loadedEntities = $this->fixturesLoader->getFixtures(); // get loaded entities