A Symfony bundle to manage fixtures with nelmio/alice and fzaninotto/Faker.
Currently supports Doctrine ORM and Doctrine ODM.
- Install
- Basic usage
- Advanced usage
- Custom Faker Providers
- Custom Alice Processors
- DoctrineFixturesBundle support
- Resources
Other references:
First you need install appropriate database managers (if you didn't install it yet), according to your project requirements. Check the documentation here.
You can use Composer to install the bundle to your project:
composer require --dev hautelook/alice-bundle doctrine/data-fixturesOf course, the doctrine/data-fixtures library is only needed if you're using Doctrine.
Then, enable the bundle by updating your app/AppKernel.php file to enable the bundle:
<?php
// app/AppKernel.php
public function registerBundles()
{
//...
if (in_array($this->getEnvironment(), ['dev', 'test'])) {
//...
$bundles[] = new Hautelook\AliceBundle\HautelookAliceBundle();
}
return $bundles;
}Configure the bundle to your needs (example with default values):
# app/config/config_dev.yml
hautelook_alice:
db_drivers:
orm: ~ # Enable Doctrine ORM if is registered
mongodb: ~ # Enable Doctrine ODM if is registered
phpcr: ~ # Enable Doctrine PHPCR ODM if is registered
locale: en_US # Locale to used for faker; must be a valid Faker locale otherwise will fallback to en_US
seed: 1 # A seed to make sure faker generates data consistently across runs, set to null to disable
persist_once: false # Only persist objects once if multiple files are passed
loading_limit: 5 # Maximum number of time the loader will try to load the files passedFore more information regarding the locale, refer to Faker documentation on localization.
Assuming you are using Doctrine, make sure you
have the doctrine/doctrine-bundle and doctrine/data-fixtures packages installed.
Then create a fixture file in src/AppBundle/DataFixtures/ORM:
# src/AppBundle/DataFixtures/ORM/dummy.yml
AppBundle\Entity\Dummy:
dummy_{1..10}:
name: <name()>
related_dummy: '@related_dummy*'# AppBundle/DataFixtures/ORM/related_dummy.yml
AppBundle\Entity\RelatedDummy:
related_dummy_{1..10}:
name: <name()>Then simply load your fixtures with the doctrine command php app/console fixtures:load.
If you want to load the fixtures of a bundle only, do php app/console fixtures:load -b MyFirstBundle -b MySecondBundle.
See more.
Next chapter: Advanced usage
- Behat extension: AliceBundleExtension
- Bundle for generating AliceBundle compatible fixtures directly from Doctrine entities: AliceGeneratorBundle
- Upgrade guide
- Changelog
This bundle was originaly developped by Baldur RENSCH and HauteLook. It is now maintained by Théo FIDRY.