Data Providers in PHPUnit 3.2
Starting with version 3.2, PHPUnit has support for TestNG-style data providers:
<?php
class DataTest extends PHPUnit_Framework_TestCase
{
protected static $myData = array(
array(0, 0, 0),
array(0, 1, 1),
array(1, 0, 1),
array(1, 1, 3)
);
public static function provider()
{
return self::$myData;
}
/**
* @dataProvider provider
*/
public function testAdd($a, $b, $c)
{
$this->assertEquals($c, $a + $b);
}
}
?>
@dataProvider annotation returns an array or an Iterator object that contain argument arrays. For each of these arrays a test object is created that will run the test method with the argument from the array:sb@vmware ~ % phpunit DataTest PHPUnit 3.2.0-dev by Sebastian Bergmann. ...F Time: 0 seconds There was 1 failure: 1) testAdd(DataTest) with data (1, 1, 3) Failed asserting that <integer:2> matches expected value <integer:3>. /home/sb/DataTest.php:21 FAILURES! Tests: 4, Failures: 1.
