Parameterized Tests in PHPUnit

In JUnit, you can use the @RunWith annotation (Parameterized.class) to run one unit test several times with different actual and expected results. I am new to PHPUnit, so I would like to know which of the proposed approaches to achieve the same (one unit test works with many actual expected results)?

+6
source share
1 answer

You can use the so-called data provider . Like this:

/** * @dataProvider providerPersonData */ public function testPerson($name, $age) { // test something ... } public function providerPersonData() { // test with this values return array( array('foo', 36), array('bar', 99), // ... ); } 

You define the data provider using the @dataProvider annotation.

+10
source

All Articles