Data Providers
A test method can accept any parameter. These parameters can be provided by a data provider method (provider () in the following example).
The data provider method is declared with @dataprovider.
A data provider method must be public, can return a set of arrays, or it can return an object that inherits from the iterator interface and produces an array based on each step iteration.
For each array is part of the collection, and the test method invokes the array contents as its arguments.
Code
1 2 class Datatest extends Phpunit_framework_testcase
3 {
4/* *
5 * @dataProvider Provider
6 */
7 Public Function Testadd ($a, $b, $c)
8 {
Assertequals 9 $this ($c, $a + $b);
10}
11
Public function provider ()
13 {
The return Array (
Array (0, 0, 0),
Array (0, 1, 1),
Array (1, 0, 1),
Array (1, 1, 3)
19);
20}
21}
?>
PHPUnit Datatest
PHPUnit 3.4.2 by Sebastian Bergmann.
... F
time:0 seconds
There was 1 failure:
1) Testadd (datatest) with data (1, 1, 3)
Failed asserting that matches expected value .
/home/sb/datatest.php:21
failures!
Tests:4, Assertions:4, failures:1.
In the above example, the fourth set of data tests did not pass.
* When a test accepts parameters from both the @dataprovider method and one or more @depends methods, the parameters from the data provider will precede the parameters from the @depends.