First in the test use @dataProvider
annotation and instantiate JsonFileDataProviderIterator
in the data provider method, passing in the test file (__FILE__
) and some namespace (something
):
<?php
use \JsonFileDataProviderIterator;
class MyTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider someDataProvider
*/
public function testSomething($data)
{
// ...
}
public function someDataProvider()
{
return new JsonFileDataProviderIterator(__FILE__, 'something');
}
}
Then setup a directory next to the test file with the same name replacing .php
with .data
, organize json data files into subdirectories matching the namespace used in the test (something
).
+ MyTest.php
+ MyTest.data/
|--+ something/
| |--+ some_simple_scenario.json
| |--+ some_crazy_scenario.json
Check this out: https://github.com/redaxmedia/phpunit-provider-autoloader