henryruhs / phpunit-autoprovide

PHPUnit 中自动加载 CSV、JSON、PHP、XML 和 YAML 数据提供者的魔法助手

6.0.0 2022-04-05 20:37 UTC

This package is auto-updated.

Last update: 2024-09-14 11:38:23 UTC


README

PHPUnit 中自动加载 CSV、JSON、PHP、XML 和 YAML 数据提供者的魔法助手。

Build Status Packagist Version License

安装

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"
	]
]