ivansabik
ivansabik

Reputation: 613

Parametrized tests in PHPUnit

On JUnit, you can use the annotation @RunWith(Parameterized.class) to run a single unit test several times with different actual and expected results. I'm new to PHPUnit so I would like to know which are suggested approachs for achieving the same (running one unit test with many actual, expected results)?

Upvotes: 17

Views: 5637

Answers (1)

hek2mgl
hek2mgl

Reputation: 158110

You can use a 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.

Upvotes: 30

Related Questions