PhpUnit内联数据提供程序


PhpUnit inline DataProvider

有没有办法直接在注释中指定测试参数?类似这样的东西:

 /**
 * @dataProvider [[0, 0, 0], [0, 1, 1], [1, 0, 1]]
 */
public function testAdd($a, $b, $expected)
{
    $this->assertEquals($expected, $a + $b);
}

因为当DataProvider只与简单数据集一起使用一次时,它会很有用。

感谢Sebastian Bergmann,解决方案是使用@testWith:

 /**
 * @testWith [0, 0, 0]
 *           [0, 1, 1]
 *           [1, 1, 2]
 *           [1, 0, 1]
 */
public function testAdd($a, $b, $c)
{
    $this->assertEquals($c, $a + $b);
}

您所描述的内容已添加到PHPUnit 4.8中。