Extensions for PHPUnit to provide additional functionality.
- Available as Composer package eloquent/phpunit-extensions.
- API documentation available.
Parameterized test cases allow entire PHPUnit test cases to be run in multiple different configurations. They operate similar to PHPUnit's own data providers, but on a test case level rather than a test method level.
To create a parameterized test case, extend the ParameterizedTestCase
class
instead of PHPUnit_Framework_TestCase
, and implement the required methods:
use Eloquent\Phpunit\ParameterizedTestCase;
class ExampleTest extends ParameterizedTestCase
{
public function getTestCaseParameters()
{
return array(
array('Ocelot', 'Lapis lazuli', 'Dandelion'),
array('Sloth', 'Carbon', 'Conifer'),
);
}
public function setUpParameterized($animal, $mineral, $vegetable)
{
// set up...
}
public function tearDownParameterized($animal, $mineral, $vegetable)
{
// tear down...
}
public function testSomething()
{
// test...
}
}
Every test in the testcase will now be run once for each entry in the
getTestCaseParameters()
method.