zenify / doctrine-fixtures
v4.2
2016-12-28 23:52 UTC
Requires
- php: ^7.0
- fzaninotto/faker: ~1.6
- kdyby/doctrine: ~3.1
- nelmio/alice: ~2.2
- nette/di: ~2.4
- nette/finder: ~2.4
- nette/reflection: ~2.4
- symfony/console: ^3.0
- tracy/tracy: ~2.4
Requires (Dev)
- nette/bootstrap: ~2.4
- phpunit/phpunit: ^5.6
- zenify/coding-standard: ^4.0
README
将 nelmio/alice 集成到 Nette DI。此软件包为 Alice 添加了 .neon
支持。
Alice 使用 fzaninotto/Faker 生成假数据,因此请确保也检查它。
安装
composer require zenify/doctrine-fixtures
注册扩展
# app/config/config.neon extensions: - Kdyby\Annotations\DI\AnnotationsExtension - Kdyby\Events\DI\EventsExtension doctrine: Kdyby\Doctrine\DI\OrmExtension fixtures: Zenify\DoctrineFixtures\DI\FixturesExtension
配置
# default values fixtures: locale: "cs_CZ" # e.g. change to en_US in case you want to use English seed: 1
对于所有支持的地区,只需检查 Faker Providers。
用法
我们可以加载具有特定固定结构 .neon
/.yaml
文件。Alice 将它们转换为实体并插入到数据库中。要了解固定文件,请参阅 nelmio/alice 的 README。
例如,此固定文件将创建 100 个具有生成名称的产品
fixtures/products.neon
Zenify\DoctrineFixtures\Tests\Entity\Product: "product{1..100}": __construct: ["<shortName()>"]
您还可以包含其他固定文件
fixtures/products.neon
include: - categories.neon Zenify\DoctrineFixtures\Tests\Entity\Product: "product{1..100}": __construct: ["<shortName()>"] category: "@category@brand<numberBetween(1, 10)>"
fixtures/categories.neon
Zenify\DoctrineFixtures\Tests\Entity\Category: "category{1..10}": __construct: ["<shortName()>"]
然后我们可以加载它们
use Zenify\DoctrineFixtures\Contract\Alice\AliceLoaderInterface; class SomeClass { /** * @var AliceLoaderInterface */ private $aliceLoader; public function __construct(AliceLoaderInterface $aliceLoader) { $this->aliceLoader = $aliceLoader; } public function loadFixtures() { // arg can be used file(s) or dir(s) with fixtures $entities = $this->aliceLoader->load(__DIR__ . '/fixtures'); // ... } }
就是这样!
测试
composer check-cs vendor/bin/phpunit
贡献
规则很简单
- 新功能需要测试
- 所有测试都必须通过
- 每个 PR 一个功能
我们很高兴合并您的功能!