Re: PHPUnit - how to run with multiple data sets?
| From: | Greg Beaver | Date: | Wed, 02 Jun 2004 02:16:23 +0000 |
| Subject: | Re: PHPUnit - how to run with multiple data sets? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12820@lists.php.net to get a copy of this message | ||
Nola Stowe wrote:
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:it's a good start :) try using this instead foreach ($data as $i => $d) {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???
$this->assertEquals($d, checkValidZip($d[0], $d[1]), "result $i failed, $d[0] => $d[1]");} This will help you because the message displayed will contain the input that generated an error. Greg