PHPUnit - how to run with multiple data sets?
| From: | Stowe, Nola | Date: | Tue, 01 Jun 2004 19:16:21 +0000 |
| Subject: | PHPUnit - how to run with multiple data sets? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-12817@lists.php.net to get a copy of this message | ||
I want to run a function with multiple sets of data. I can't use
PHPUnit2 yet (not to php 5 yet) so I am using PHPUnit and this is one of my
test functions:
function testCheckValidZip() {
$data = array(); $results = array();
$data[] = array("60950", "US"); $results[] = true;
$data[] = array("1234", "usa"); $results[] = false;
$data[] = array("01234", "usa"); $results[] = true;
$data[] = array("zip", "u.s."); $results[] = false;
$data[] = array("", "usa"); $results[] = true;
$data[] = array("", ""); $results[] = true;
$data[] = array("60950-5121", "united states"); $results[] =
true;
$data[] = array("3215-4554", "us"); $results[] = false;
$data[] = array("01234-5748", "USA"); $results[] = true;
foreach($data as $d) {
$checkedResults[] = checkValidZip($d[0], $d[1] );
}
$this->assertEquals($checkedResults, $results);
}
checkValidZip is a function that returns true/false. I put the
expected value in the $results array, and then compare the final two arrays
in assertEquals. Not bad, and it works, but there's gotta be a better way to
use PHPUnit to do this???
Thanks :)
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
The information in this email and any attachments may contain
confidential information that is intended solely for the
attention and use of the named addressee(s). This message or
any part thereof must not be disclosed, copied, distributed or
retained by any person without authorization from the addressee.
If you are not the intended addressee, please notify the sender
immediately, and delete this message.
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>