If you use the same code with a different data set and you expect similar output, you can use the dataProvider() function
Example adapted from PHPUnit docs:
<?php class DataTest extends PHPUnit_Framework_TestCase { public function testAdd($sample, $data, $result) { $this->assertEquals($result, Foo::bar($sample, $data); } public function provider() { return array( array(0, 0, 0), array(0, 1, 1), array(1, 0, 1), array(1, 1, 3) ); } }
if you have completely different return values / structures, for example, it returns XML and JSON depending on the input, then it is preferable to use several tests, since you can use the correct assert[Xml/Json]StringMatches() functions, and you will get the best error result.
For additional error checks, I would recommend adding additional testing methods:
public function testError() { Foo::bar("invalidArgument"); }
source share