henryruhs/phpunit-autoprovide

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

6.0.0 2022-04-05 20:37 UTC

This package is auto-updated.

Last update: 2024-05-14 11:03:34 UTC


README

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

Build Status Packagist Version License

Installation

composer require henryruhs/phpunit-autoprovide

Setup

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__;
}

Usage

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