Magic helper to autoload CSV, JSON, PHP, XML and YAML data provider in PHPUnit.
composer require henryruhs/phpunit-autoprovide
Create the TestCaseAbstract
for your testing suite:
<?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__;
}
Extend ExampleTest
from TestCaseAbstract
and set @dataProvider
as needed:
<?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');
}
}
Create the ExampleTest{_testMethod}.{csv|json|php|xml|yml}
file:
[
[
"test"
]
]