Re: PHPUnit bugs/fixes
| From: | Wolfram Kriesing | Date: | Mon, 19 Aug 2002 08:39:02 +0000 |
| Subject: | Re: PHPUnit bugs/fixes | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-8498@lists.php.net to get a copy of this message | ||
I am getting back to this.
who uses PHPUnit (extensively), please jump in and lets solve this!
I think a good test platform should be tested too :-) and we need a good test platform for all the packages
(BTW i think all the packages (including those i am maintaining) should have a PHPUnit test, so verification would be an easy task)
Wolfram
Wolfram Kriesing wrote:
Alan Knowles wrote:-- Wolfram ... translating template engine .... http://sf.net/projects/simpletpl ... authentication system .... http://sf.net/projects/authobviously - if they are failing like this - the default behaviour is actually 100% correct for a 'anally retentive' unit test :) I guess you are looking for a more 'loose' match there. eg. a == rather than a ===i can not really agree on that one, since PHP is a type-less language i expect 7=='7' to be true should another method not assertEquals but assert<SomethingElse> be used or introduced? to show the code i am working on:$newData = array( 'login' => 'cain', 'password' => '0', 'name' => 'Lutz Testern', 'address_id'=> 0, 'company_id'=> 0 ); // save the user in the DB and return the id generated $userId = addUser( $newData ); // save the userId in the array so it contains the same // data as teh row in the DB $newData['id'] = $userId;// $db is an instance of PEAR::DB $dbData = $db->getRow('SELECT * FROM user WHERE id='.$userId); $this->assertEquals( $newData , $dbData , 'Insert failed!');now the problem is that the $db->getRow returns the data all as stringsa:6:{s:10:"address_id";s:1:"0";s:10:"company_id";s:1:"0"; ...but the content is the same, even though the types are not the samea:6:{s:10:"address_id";i:0; s:10:"company_id";i:0; ...since db->getRow doesnt know the actual types so this case could never be tested this way! but how?Wolfram Kriesing wrote:i was using PHPUnit for some testing, 2 problems occured comparing arrays usingserialize($expected) != serilaize($actual)is not succedding because of 1. the order of the keys is not the sameksort($expected); ksort($actual); serialize($expected) != serilaize($actual)this helps 2.even if the values are the same the types might not be see: a:6:{s:10:"address_id";i:0; s:10:"company_id";i:0; ... a:6:{s:10:"address_id";s:1:"0";s:10:"company_id";s:1:"0"; ...one solutions would be the array has to be foreach'ed to set all the types to 'string' and compare it then, that should workany easier ways?