zenstruck/foundry
Composer 安装命令:
composer require --dev zenstruck/foundry
包简介
A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
README 文档
README
"Fixtures you'll actually enjoy writing!"
Foundry turns fixture creation into a joy, via an expressive, auto-completable, on-demand fixtures system with Symfony and Doctrine:
$post = PostFactory::new() // Create the factory for Post objects ->published() // Make the post in a "published" state ->create([ // create & persist the Post object 'slug' => 'post-a' // This Post object only requires the slug field - all other fields are random data ]) ;
The factories can be used inside DoctrineFixturesBundle to load fixtures or inside your tests, where it has even more features.
Foundry supports doctrine/orm (with doctrine/doctrine-bundle),
doctrine/mongodb-odm (with doctrine/mongodb-odm-bundle)
or a combination of these.
Want to watch a screencast 🎥 about it? Check out https://symfonycasts.com/foundry
How to contribute
Running the Test Suite
The test suite of this library needs one or more databases, then it comes with a docker compose configuration.
Note
Docker and PHP installed locally (with mysql, pgsql & mongodb extensions) is required.
You can start the containers and run the test suite:
# start the container $ docker compose up --detach # install dependencies $ composer update # run main testsuite (with "schema" reset database strategy) $ ./phpunit # run "reset-database" testsuite $ ./phpunit --testsuite reset-database
Overriding the default configuration
You can override default environment variables by creating a .env.local file, to easily enable permutations:
# .env.local # change the database to postgreSQL... DATABASE_URL="postgresql://zenstruck:zenstruck@127.0.0.1:5433/zenstruck_foundry?serverVersion=15" # ...or to SQLite DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" MONGO_URL="" # disables Mongo USE_DAMA_DOCTRINE_TEST_BUNDLE="1" # enables dama/doctrine-test-bundle PHPUNIT_VERSION="11" # possible values: 9, 10, 11, 11.4 # test reset database with migrations, # only relevant for "reset-database" testsuite DATABASE_RESET_MODE="migrate" MIGRATION_CONFIGURATION_FILE="tests/Fixture/MigrationTests/configs/migration-configuration.php" # run test suite with postgreSQL $ vendor/bin/phpunit
The .env.local file can also be used to override the port of the database containers,
if it does not meet your local requirements. You'll also need to override docker compose configuration:
Here is an example to use MySQL on port 3308:
# docker-compose.override.yml version: '3.9' services: mysql: ports: - "3308:3306"
# .env.local DATABASE_URL="mysql://root:1234@127.0.0.1:3308/foundry_test?serverVersion=5.7.42"
Run the tests locally faster
As long as you don't want to test Mongo, you can use the following .env.local file to run the tests faster locally:
# dama/doctrine-test-bundle makes Foundry testsuite really faster USE_DAMA_DOCTRINE_TEST_BUNDLE="1" # using both ODM and ORM makes the "reset db" mechanism slower MONGO_URL="" # Use the last version of PHPUnit PHPUNIT_VERSION="12" # Enable all features of Foundry USE_FOUNDRY_PHPUNIT_EXTENSION="1"
"maker" tests are also quite slow, so you can skip them with using the following command:
$ ./phpunit --exclude-group=maker
Enjoy blazing fast tests! 🚀
Running the documentation linter locally
This section provides guidance on how to run the documentation linter, contained within a Docker image, locally on your machine. This linter is designed to verify and ensure that the document syntax adheres to the required standards.
The following command runs the linter in the local directory:
docker run --rm -it -e DOCS_DIR='/docs' -v ${PWD}/docs:/docs oskarstark/doctor-rst:latest
Credit
The AAA style of testing was first introduced to me by Adam Wathan's excellent Test Driven Laravel Course. The inspiration for this libraries API comes from Laravel factories and christophrumpel/laravel-factories-reloaded.
Security Policy
If you discover a security vulnerability, please do not open a public issue or pull request. Instead, please review this repository's Security Policy for instructions on how to report it responsibly.
zenstruck/foundry 适用场景与选型建议
zenstruck/foundry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.53M 次下载、GitHub Stars 达 789, 最近一次更新时间为 2020 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「faker」 「test」 「Fixture」 「doctrine」 「factory」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zenstruck/foundry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zenstruck/foundry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zenstruck/foundry 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
The bundle for easy using json-rpc api on your project
Symfony bundle to manage fixtures with Alice and Faker.
Additional plugin for fakerphp/faker that allows you to generate a random animal
Faker Japanese is a Faker provider that generates fake Japanese related data for you.
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 13.53M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 791
- 点击次数: 36
- 依赖项目数: 97
- 推荐数: 4
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-05