A example Symfony2 Application using h4cc/AliceFixureBundle in multiple ways.
Add in your composer.json the following line to either "require" or "require-dev":
"h4cc/alice-fixtures-bundle": "dev-master"
(I recommend to follow a stable version if available)
Then update your packages
php composer.phar update
After that, add the Bundle to your AppKernel.
A configuration is optional.
Check out the default configuration.
Use this command to get a up-to-date config reference:
php app/console config:dump-reference h4cc_alice_fixtures
Fixtures are stored in YAML files which can be used in a number of ways:
- use app/console to load the fixtures into the database
- use the fixtures in PHPUnit tests
- use the fixtures in Selenium tests
A simple fixture file is the default.yml
A couple of fixture files can be combined to a set. This is done with a simple PHP script, see CustomerDefaultSet.php for an example. Any file that is named after the pattern "DataFixtures/Alice/*Set.php" will be recognized automatically as a set.
Sets can be automatically loaded by this command:
php app/console h4cc_alice_fixtures:load:sets
The configuration of a provider can be found in the services.yml.
The referenced "CategoryProvider" class add a method called "categoryName", which can be used in the fixture files like this: "<categoryName()>". For example here in categories.yml.
The test UserControllerTest as a setUp() Method, which will clear the database and load the given fixtures. This way functional tests could be done, that demand a specific dataset.
The controller SeleniumController contains a action for loading a defined fixture set. This way, a browser test could force the reset of the database for predictable tests.