henryruhs / phpunit-autoprovide
PHPUnit 中自动加载 CSV、JSON、PHP、XML 和 YAML 数据提供者的魔法助手
6.0.0
2022-04-05 20:37 UTC
Requires
- php: ^8
- phpunit/phpunit: ^9
- symfony/property-access: ^6
- symfony/serializer: ^6
- symfony/yaml: ^6
Requires (Dev)
- isnotdefined/phpcs-config: 2.0.0
- squizlabs/php_codesniffer: 3.6.2
This package is auto-updated.
Last update: 2024-09-14 11:38:23 UTC
README
PHPUnit 中自动加载 CSV、JSON、PHP、XML 和 YAML 数据提供者的魔法助手。
安装
composer require henryruhs/phpunit-autoprovide
设置
为您的测试套件创建 TestCaseAbstract
<?php namespace ExampleProject\Tests; use PHPUnitAutoProvide; /** * TestCaseAbstract * * @package ExampleProject * @category Tests */ abstract class TestCaseAbstract extends PHPUnitAutoProvide\TestCaseAbstract { /** * directory of the provider */ protected $_providerDirectory = 'tests' . DIRECTORY_SEPARATOR . 'provider'; /** * namespace of the testing suite */ protected $_testNamespace = __NAMESPACE__; }
使用方法
从 TestCaseAbstract 扩展 ExampleTest 并根据需要设置 @dataProvider
<?php namespace ExampleProject\Tests; /** * ExampleTest * * @package ExampleProject * @category Tests */ class ExampleTest extends TestCaseAbstract { /** * testMethod * * @param string $expect * * @dataProvider autoProvide */ public function testMethod(string $expect) : void { $this->assertEquals($expect, 'test'); } }
创建 ExampleTest{_testMethod}.{csv|json|php|xml|yml} 文件
[
[
"test"
]
]