Magic helper to autoload JSON files for data providers in PHPUnit
Switch branches/tags
Nothing to show
Clone or download

README.md

PHPUnit Provider Autoloader

Magic helper to autoload JSON files for data providers in PHPUnit.

Build Status Packagist Version License

Installation

composer require redaxmedia/phpunit-provider-autoloader

Usage

Create the TestCaseAbstract for your testing suite:

<?php
namespace ExampleProject\Tests;

use PHPUnitProviderAutoloader;

/**
 * TestCaseAbstract
 *
 * @since 1.0.0
 *
 * @package ExampleProject
 * @category Tests
 */

abstract class TestCaseAbstract extends PHPUnitProviderAutoloader\TestCaseAbstract
{
	/**
	 * directory of the provider
	 *
	 * @var string
	 */

	protected $_providerDirectory = 'tests' . DIRECTORY_SEPARATOR . 'provider';
    	
	/**
	 * namespace of the testing suite
	 *
	 * @var string
	 */

	protected $_testNamespace = __NAMESPACE__;
}

Extend ExampleTest from TestCaseAbstract to autoload the tests\provider\ExampleTest{_testMethod}.json file:

<?php
namespace ExampleProject\Tests;

/**
 * ExampleTest
 *
 * @since 1.0.0
 *
 * @package ExampleProject
 * @category Tests
 */

class ExampleTest extends TestCaseAbstract
{
	/**
	 * testMethod
	 *
	 * @since 1.0.0
	 *
	 * @param string $expect
	 *
	 * @dataProvider providerAutoloader
	 */

	public function testMethod(string $expect = null)
	{
		$this->assertEquals($expect, 'test');
	}
}