codekandis / phpunit
`codekandis/phpunit` 是一个库,为 `PHPUnit` 包提供多个包装和辅助类。
4.0.0
2022-08-28 19:12 UTC
Requires
- php: >=8.1
- dms/phpunit-arraysubset-asserts: ^0
- phpunit/phpunit: ^9
Requires (Dev)
- rector/rector: ^0
- roave/security-advisories: dev-master
README
此库为 phpunit/phpunit
包提供多个包装和辅助类。
索引
安装
使用以下命令安装最新版本:
$ composer require --dev codekandis/phpunit
如何使用
使用测试用例包装器
创建一个新的测试用例并从包装器 TestCase
继承。
class FooTest extends TestCase { }
使用数据提供者接口
创建一个新的数据提供者并实现接口 DataProviderInterface
。
class ImportantStuffDataProvider implements DataProviderInterface { #[Override] public static function provideData(): iterable { return [ 0 => [ 23, 42 ], 1 => [ 'foo', 'bar' ] ]; } }
在测试用例中使用数据提供者。
<?php declare( strict_types = 1 ); use CodeKandis\PhpUnit\TestCase; class FooTest extends TestCase { #[DataProviderExternal( ImportantStuffDataProvider::class, 'provideData' )] testImportantStuff( string $value1, string $value2 ) { } }