Stars: 289
Forks: 67
Pull Requests: 142
Issues: 82
Watchers: 10
Last Updated: 2023-05-04 07:09:45
Nelmio Alice extension to persist the loaded fixtures.
License: MIT License
Languages: PHP, Makefile
Alice 3.x no longer ships with a persistence layer, so this library provides one!
Supports:
The full configuration reference is:
# app/config/config.yml
# Default config
fidry_alice_data_fixtures:
default_purge_mode: ~ # default is "delete" but you can change it to "truncate" or "no_purge"
db_drivers:
doctrine_orm: ~
doctrine_mongodb_odm: ~
doctrine_phpcr_odm: ~
eloquent_orm: ~
For each driver, is the appropriate bundle is detected, e.g. DoctrineORMBundle for Doctrine and WouterJEloquentBundle
for Eloquent, the services related to those driver will be enabled. If you want to skip those checks you can turn
a specific driver to true
instead. If you want to disable a specific driver, simply force the value false
instead.
Create a fixture file in src/AppBundle/Resources/fixtures
:
# src/AppBundle/Resources/fixtures/dummy.yml
AppBundle\Entity\Dummy:
dummy_{1..10}:
name: <name()>
related_dummy: '@related_dummy*'
# src/AppBundle/Resources/fixtures/related_dummy.yml
AppBundle\Entity\RelatedDummy:
related_dummy_{1..10}:
name: <name()>
Then you can load those files using a LoaderInterface
:
<?php
$files = [
'path/to/src/AppBundle/Resources/fixtures/dummy.yml',
'path/to/src/AppBundle/Resources/fixtures/related_dummy.yml',
];
// Choose your loader
$loader = $container->get('fidry_alice_data_fixtures.loader.doctrine'); // For Doctrine ORM
$loader = $container->get('fidry_alice_data_fixtures.loader.doctrine_mongodb'); // For Doctrine MongoDB ODM
$loader = $container->get('fidry_alice_data_fixtures.loader.doctrine_phpcr'); // For Doctrine PHPCR
$loader = $container->get('fidry_alice_data_fixtures.loader.eloquent'); // For Eloquent ORM
// Purge the objects, create PHP objects from the fixture files and persist them
$objects = $loader->load($files);
// $objects is now an array of persisted `Dummy` and `RelatedDummy`
Warning: loading the objects does not trigger a clear()
. This means if
you are relying on some Doctrine life-cycle events in your tests, some may not
be triggered as expected. See #84 For more information.
Check the advance usage entry.
Clone the project
To launch Docker containers for databases, run make start_databases
Run tests with make test
.
To stop containers for databases, run make stop_databases