zenify/doctrine-fixtures
最新稳定版本:v4.2
Composer 安装命令:
composer require zenify/doctrine-fixtures
包简介
Doctrine Fixtures, Faker and Alice integration into Nette
README 文档
README
Integration of nelmio/alice to Nette DI.
This package adds .neon support to Alice.
Alice uses fzaninotto/Faker to generate fake data, so be sure to check that too.
Install
composer require zenify/doctrine-fixtures
Register extensions:
# app/config/config.neon extensions: - Kdyby\Annotations\DI\AnnotationsExtension - Kdyby\Events\DI\EventsExtension doctrine: Kdyby\Doctrine\DI\OrmExtension fixtures: Zenify\DoctrineFixtures\DI\FixturesExtension
Configuration
# default values fixtures: locale: "cs_CZ" # e.g. change to en_US in case you want to use English seed: 1
For all supported locales, just check Faker Providers.
Usage
We can load .neon/.yaml with specific fixtures structure. Alice turns them into entities and inserts them to database. To understand fixture files, just check the README of nelmio/alice.
For example, this fixture will create 100 products with generated name:
fixtures/products.neon
Zenify\DoctrineFixtures\Tests\Entity\Product: "product{1..100}": __construct: ["<shortName()>"]
You can also include other fixtures
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()>"]
And then we can load them:
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'); // ... } }
That's it!
Testing
composer check-cs vendor/bin/phpunit
Contributing
Rules are simple:
- new feature needs tests
- all tests must pass
- 1 feature per PR
We would be happy to merge your feature then!
zenify/doctrine-fixtures 适用场景与选型建议
zenify/doctrine-fixtures 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.34k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2014 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 zenify/doctrine-fixtures 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zenify/doctrine-fixtures 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-04