Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpUnit inline DataProvider

Tags:

php

phpunit

Is there a way to specify the test parameters directly in the annotation ? Something like this :

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

Because it can be useful when the DataProvider is used only once with simple data set.

like image 241
Mohamed Ramrami Avatar asked Dec 03 '22 15:12

Mohamed Ramrami


1 Answers

Thanks to Sebastian Bergmann, the solution is to use @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);
}
like image 96
Mohamed Ramrami Avatar answered Dec 06 '22 11:12

Mohamed Ramrami