theofidry / alice-data-fixtures
Nelmio alice extension to persist the loaded fixtures.
Fund package maintenance!
theofidry
Installs: 22 089 743
Dependents: 76
Suggesters: 4
Security: 0
Stars: 311
Watchers: 10
Forks: 71
Open Issues: 8
Requires
- php: ^8.3
- nelmio/alice: ^3.10
- psr/log: ^1 || ^2 || ^3
- webmozart/assert: ^1.10
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.4.1
- doctrine/annotations: ^1.13
- phpspec/prophecy: ^1.14.0
- phpspec/prophecy-phpunit: ^2.0.1
- phpunit/phpunit: ^9.5.10
- symfony/phpunit-bridge: ^5.3.8 || ^6.4 || ^7.0
Suggests
- alcaeus/mongo-php-adapter: To use Doctrine with the MongoDB flavour
- doctrine/data-fixtures: To use Doctrine
- doctrine/dbal: To use Doctrine with the PHPCR flavour
- doctrine/mongodb: To use Doctrine with the MongoDB flavour
- doctrine/mongodb-odm: To use Doctrine with the MongoDB flavour
- doctrine/orm: To use Doctrine ORM
- doctrine/phpcr-odm: To use Doctrine with the PHPCR flavour
- illuminate/database: To use Eloquent
- jackalope/jackalope-doctrine-dbal: To use Doctrine with the PHPCR flavour
- ocramius/proxy-manager: To avoid database connection on kernel boot
Conflicts
- doctrine/data-fixtures: <1.7.0
- doctrine/dbal: <3.0
- doctrine/doctrine-bundle: <2.11.0
- doctrine/mongodb-odm: <2.6.0
- doctrine/mongodb-odm-bundle: <5.1.0
- doctrine/orm: <2.20
- doctrine/persistence: <2.0
- doctrine/phpcr-bundle: <3.0
- doctrine/phpcr-odm: <2.0.0
- illuminate/database: <10.0
- ocramius/proxy-manager: <2.1
- symfony/framework-bundle: >=6.0 <6.4
- zendframework/zend-code: <3.3.1
- dev-master / 1.x-dev
- 1.8.0
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.0
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.1
- 1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v1.0.0-rc.2
- v1.0.0-rc.1
- v1.0.0-rc.0
- v1.0.0-beta.5
- v1.0.0-beta.4
- v1.0.0-beta.3
- v1.0.0-beta.2
- v1.0.0-beta.1
- v1.0.0-beta.0
- dev-chore/sf-7
- dev-santoslluis/master
- dev-TeDo-Verlag/master
- dev-entity-persister
- dev-test/sf-bridge
- dev-fix/eloquent-min-compat
- dev-fix/doctrine-orm-min-compat
- dev-ci/composer-bug
- dev-ci/composer-install
- dev-test/fixx
- dev-test/local
- dev-fix/eloquent
- dev-fix/doctrine-cr
- dev-feat/drop-sf54
- dev-feat/php83
- dev-chore/php82
- dev-bugfix/ci
- dev-bugfix/deprecations
- dev-theofidry-patch-2
- dev-theofidry-patch-1
- dev-feature/multiple-entity-managers
This package is auto-updated.
Last update: 2024-11-13 15:39:30 UTC
README
Alice 3.x no longer ships with a persistence layer, so this library provides one!
Supports:
- Symfony 6.4+
- Doctrine ORM 2.20+
- Doctrine ODM 2.0+
- Doctrine PHPCR 2.0+
- Eloquent 11.0+
Documentation
Configuration
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, if 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.
Basic usage
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.
Advanced Usage
Check the advance usage entry.
Contributing
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