richcongress / unit-bundle
Symfony 4+ 的单元包
v1.0.2
2020-02-28 09:09 UTC
Requires
- php: >=7.3
- ext-json: *
- brianium/paratest: ^3.1
- dama/doctrine-test-bundle: ^6.3
- doctrine/doctrine-bundle: ^2.0
- doctrine/doctrine-fixtures-bundle: ^3.2
- doctrine/orm: ^2.6
- liip/functional-test-bundle: ^3.0
- liip/test-fixtures-bundle: ^1.0
- mockery/mockery: ^1.0
- phpunit/phpunit: ^7.5
- symfony/config: ^4.0
- symfony/console: ^4.0
- symfony/dependency-injection: ^4.0
- symfony/phpunit-bridge: ^4.0
- symfony/serializer: ^4.0
- symfony/validator: ^4.0
Requires (Dev)
- eightpoints/guzzle-bundle: ^7.6
- php-coveralls/php-coveralls: ^2.1
- symfony/form: ^4.0
- symfony/orm-pack: ^1.0
- symfony/security-bundle: ^4.0
- symfony/yaml: ^4.0
This package is auto-updated.
Last update: 2024-08-29 06:12:49 UTC
README
此版本的包需要 Symfony 4.4+ 和 PHP 7.3+。
unit-bundle 提供了一套应用测试工具。它提供了隔离测试的包装器,各种测试用例以避免代码冗余,以及简单的固定数据管理。
此包是基于 chaplean/unit-bundle 的分支。
快速开始
unit-bundle 几乎不需要配置,但提供了一些有用的工具来测试您的代码。以下是一个基本示例
class MainControllerTest extends ControllerTestCase { /** * @WithFixtures * * @return void */ public function testIndex(): void { $client = self::createClient(); $client->request('GET', '/'); self::assertStatusCode(Response::HTTP_OK, $client); } /** * @WithFixtures * * @return void */ public function testUserEdition(): void { $client = $this->createClientWith('user-1'); $client->request('PUT', '/rest/users/self', ['name' => 'Karl']); self::assertStatusCode(Response::HTTP_OK, $client); $content = self::getJsonContent($client); self::assertArrayKeyExists('name', $content); self::assertSame('Karl', $content['name']); } }
目录
1. 安装
此版本的包需要 Symfony 4.4+ 和 PHP 7.3+。
1.1 Composer
composer require richcongress/unit-bundle
1.2 包声明
安装后,请确保这些4个包已正确在Kernel的包列表中声明。
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['test' => true], new Liip\FunctionalTestBundle\LiipFunctionalTestBundle::class => ['test' => true], new Liip\TestFixturesBundle\LiipTestFixturesBundle::class => ['test' => true], new RichCongress\Bundle\UnitBundle\RichCongressUnitBundle::class => ['test' => true],
1.3 声明PHP扩展
首先,在 phpunit.xml.dist
中声明PHPUnitExtension。
... <extensions> <extension class="RichCongress\Bundle\UnitBundle\PHPUnit\PHPUnitExtension" /> </extensions> ...
1.4 强制配置
默认情况下,包会自动配置所有内容,但如果配置已被覆盖,您可以通过导入配置将其重置为默认值。
imports: - { resource: '@RichCongressUnitBundle/Resources/config/config.yml' }
或者手动配置 doctrine,例如这样:
parameters: doctrine.dbal.connection_factory.class: Liip\TestFixturesBundle\Factory\ConnectionFactory doctrine: dbal: driver: pdo_sqlite user: test path: '%kernel.cache_dir%/test.db' url: null memory: false
2. 入门
3. 版本控制
unit-bundle 遵循 语义版本控制。简而言之,方案是 MAJOR.MINOR.PATCH,其中
- MAJOR 在有重大更改时增加,
- MINOR 在以向后兼容的方式添加新功能时增加,
- PATCH 在以向后兼容的方式修复错误时增加。
1.0.0 以下的版本被视为实验性版本,任何时间都可能发生重大更改。
4. 贡献
欢迎贡献!有许多方式可以贡献,我们感谢所有的贡献。以下是一些主要的贡献方式
- 错误报告:虽然我们努力提供高质量的软件,但错误可能发生,我们无法修复我们不知道的问题。所以,即使您不确定或者只是想提问,也请报告。无论如何,问题可能表明文档还可以进一步改进!
- 功能请求:您有一个当前API没有涵盖的使用场景?想要建议更改或添加某些内容?我们将很高兴阅读它并开始讨论,以尝试找到最佳解决方案。
- 拉取请求:想要贡献代码或文档?我们非常欢迎!如果您需要帮助开始,请参阅GitHub关于拉取请求的文档。我们使用“分支和拉取模型”,贡献者将更改推送到他们的个人分支,然后创建拉取请求到主仓库。请针对
master
分支创建您的拉取请求。
提醒一下,所有贡献者都应遵循我们的行为准则。
5. 编程技巧
您可以使用Docker和docker-compose
来修改项目。请查看以下命令。
# Start the project docker-compose up -d # Install dependencies docker-compose exec application composer install # Run tests docker-compose exec application bin/phpunit # Run a bash within the container docker-compose exec application bash
6. 许可证
unit-bundle是在MIT许可证的条款下分发的。
有关详细信息,请参阅LICENSE。