theofidry / alice-data-fixtures
Nelmio alice 扩展,用于持久化加载的 fixtures。
1.7.2
2024-07-05 21:18 UTC
Requires
- php: ^8.2
- 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
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/dbal: <3.0
- doctrine/orm: <2.6.3
- doctrine/persistence: <2.0
- illuminate/database: <8.12
- ocramius/proxy-manager: <2.1
- symfony/framework-bundle: <5.4 || >=6.0 <6.4
- zendframework/zend-code: <3.3.1
- dev-master / 1.x-dev
- 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-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-09-05 21:36:54 UTC
README
Alice 3.x 不再包含持久化层,因此这个库提供了一个!
支持
- Symfony 5.4+, 6.4+
- Doctrine ORM 2.5+
- Doctrine ODM 2.0+
- Doctrine PHPCR 1.4+
- Eloquent 8.12+
文档
配置
完整的配置参考如下:
# 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: ~
对于每个驱动,如果检测到适当的包,例如 DoctrineORMBundle 用于 Doctrine 和 WouterJEloquentBundle 用于 Eloquent,将启用相关的服务。如果您想跳过这些检查,可以将特定驱动设置为 true
。如果您想禁用特定驱动,只需将值强制设置为 false
。
基本用法
在 src/AppBundle/Resources/fixtures
中创建一个 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()>
然后您可以使用 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`
警告:加载对象不会触发 clear()
。这意味着如果您的测试依赖于一些 Doctrine 生命周期事件,那么其中一些可能不会按预期触发。请参阅 #84 以获取更多信息。
高级用法
查看高级用法入口。
贡献
克隆项目
要启动数据库 Docker 容器,请运行 make start_databases
使用 make test
运行测试。
要停止数据库容器,请运行 make stop_databases