Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.md

PHPUnit Provider Autoloader

Magic helper to autoload CSV, JSON, PHP, XML and YAML data provider 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 4.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 and set @dataProvider as needed:

<?php
namespace ExampleProject\Tests;

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

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

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

Create the ExampleTest{_testMethod}.{csv|json|php|xml|yml} file:

[
	[
		"test"
	]
]

About

Magic helper to autoload CSV, JSON, PHP, XML and YAML data provider in PHPUnit

Topics

Resources

Sponsor this project

 

Languages