3

This is a PHPUnit test:

class EqualsTest extends PHPUnit_Framework_TestCase
{
   public function testSuccess()
   {
      $this->assertEquals(array('01', 'a', 'b'), array(1, 'a', 'b'));
   }
}

'01' is a string and 1 is an integer but the test is not failling! assertEquals does not comparing types... how to overcome this problem?

user487772
  • 8,800
  • 5
  • 47
  • 72
Grigory Ilizirov
  • 1,030
  • 1
  • 8
  • 26
  • i think assertEquals() works only with the primitives like strings and numbers – volkinc Nov 12 '15 at 20:05
  • it works on arrays too... – Grigory Ilizirov Nov 12 '15 at 20:06
  • assertEquals method has an undocumented param $canonicalize. If you use $canonicalize = true, the arrays will be sorted by PHPUnit arrays comparator itself. $this->assertEquals($array1, $array2, "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = true); – volkinc Nov 12 '15 at 20:07
  • check it out http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important – volkinc Nov 12 '15 at 20:08
  • but trust me this is not good approach, write your explicit function – volkinc Nov 12 '15 at 20:10

1 Answers1

8

assertSame will work in this case.

user487772
  • 8,800
  • 5
  • 47
  • 72