Page 1 of 1

Why this test fails

Posted: Wed Oct 18, 2006 8:14 am
by kpraman
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php

   public function testing_update()
   {
      $new=new MemberTypes;
      $new->AddOrUpdateMemberType('manager','Head of the','true','','membertype');
		   
      $membertypeid=mysql_insert_id();
      $new->AddOrUpdateMemberType('commoner','Head  of  ','true',$membertypeid,'membertype');
		   
      $query=mysql_query("SELECT * FROM membertype WHERE membertypeid=$membertypeid");
      $resActual=mysql_fetch_row($query);
		  
      $resExpected=array($membertypeid,'commoner','Head of the','true');
      print_r($resActual);
      print('<br>');
      print_r($resExpected);
      $this->assertEquals($resExpected,$resActual, "UPDATE FAILED");
   }

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Oct 18, 2006 9:02 am
by sweatje
because $resExpected is not the same as $resActual

Posted: Wed Oct 18, 2006 9:17 am
by kpraman
that i know :) . But, if i compare by using array_diff i get empty.

Posted: Wed Oct 18, 2006 9:46 am
by sweatje
you don't give much to work with. you posted the test, but not the subject code, or what is being returned, either as the error message or from your print statements. If I had to guess, I would say probably your keys are in a different order between the two arrays?

Posted: Wed Oct 18, 2006 10:12 am
by kpraman
Here it is:

print("Expected");
print_r($resExpected);
print("<br>");
print("Actual");
print_r($resActual);


Output is:

ExpectedArray ( [0] => 98 [1] => commoner [2] => Head of the [3] => true )
ActualArray ( [0] => 98 [1] => commoner [2] => Head of the [3] => true )

if i user assertTrue, the test does not fail

Posted: Wed Oct 18, 2006 10:15 am
by sweatje
and what is the output of the failing test message. Do you perhaps have a trailing space on one of your strings?

Posted: Wed Oct 18, 2006 10:24 am
by John Cartwright
var_dump() is preferable over print_r in these situations. Could you show us what var_dump yields?

Posted: Thu Oct 19, 2006 12:40 am
by kpraman
var_dump output:


actual array(4) { [0]=> string(3) "152" [1]=> string(8) "commoner" [2]=> string(11) "Head of the" [3]=> string(4) "true" }
expected array(4) { [0]=> int(152) [1]=> string(8) "commoner" [2]=> string(11) "Head of the" [3]=> string(4) "true" }

Posted: Thu Oct 19, 2006 1:25 am
by jmut
kpraman wrote:var_dump output:


actual array(4) { [0]=> string(3) "152" [1]=> string(8) "commoner" [2]=> string(11) "Head of the" [3]=> string(4) "true" }
expected array(4) { [0]=> int(152) [1]=> string(8) "commoner" [2]=> string(11) "Head of the" [3]=> string(4) "true" }

so did you see why it fails....

I would guess changing

Code: Select all

$resExpected=array($membertypeid,'commoner','Head of the','true');

to

$resExpected=array((string)$membertypeid,'commoner','Head of the','true');
should work

Posted: Thu Oct 19, 2006 1:40 am
by kpraman
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am getting:

Code: Select all

$new->AddOrUpdateMemberType('commoner','Head of the','true',$membertypeid,'membertype');
         $query=mysql_query("SELECT * FROM membertype WHERE membertypeid=$membertypeid");
         $resActual=mysql_fetch_row($query);


         $resExpected=array((string)$membertypeid,'commoner','Head of the','true');



TestCase MembersTypeTest->testing_update() failed: UPDATE FAILED expected Array, actual resActual in D:\Projects\pics4news.com\classes\membertypes_testcase.php:55

Code: Select all

var_dump():

expected array(4) { [0]=> string(3) "555" [1]=> string(8) "commoner" [2]=> string(11) "Head of the" [3]=> string(4) "true" } 
actual array(4) { [0]=> string(3) "555" [1]=> string(8) "commoner" [2]=> string(11) "Head of the" [3]=> string(4) "true" } 

print_r():


expected Array ( [0] => 561 [1] => commoner [2] => Head of the [3] => true ) 
actual Array ( [0] => 561 [1] => commoner [2] => Head of the [3] => true )

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Oct 19, 2006 1:47 am
by kpraman
thanks, its working now.