Re: PHPUnit bugs/fixes
| From: | Wolfram Kriesing | Date: | Tue, 13 Aug 2002 09:09:08 +0000 |
| Subject: | Re: PHPUnit bugs/fixes | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-8348@lists.php.net to get a copy of this message | ||
Alan Knowles wrote:
obviously - 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 strings
a: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 same
a: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:-- Wolfram ... translating template engine .... http://sf.net/projects/simpletpl ... authentication system .... http://sf.net/projects/authi 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?