It looks like you want to make sure the arrays have the same key / value pairs (strongly typed), but not necessarily in the same order. So, make the orders consistent and strictly compare them.
function assertArrayEquals($a, $b) { ksort($a); ksort($b); return ($a === $b); }
As a result of testing
testAssertArrayEquals(array('a'=>1, 'b'=>2), array('a'=>1, 'b'=>2), true); testAssertArrayEquals(array('a'=>1, 'b'=>2), array('b'=>2, 'a'=>1), true); testAssertArrayEquals(array('a'=>1, 'b'=>2), array(1, 2), false); testAssertArrayEquals(array(2, 1), array(1, 2), false); testAssertArrayEquals(array('a'=>1, 'b'=>2), array('a'=>1, 'b'=>2, 'c'=>3), false); testAssertArrayEquals(array('a'=>1, 'b'=>2, 'c'=>3), array('a'=>1, 'b'=>2), false); testAssertArrayEquals(array('a'=>0,'b'=>1), array('a'=>'cake','b'=>1), false);
I would also suggest choosing the best function name; your current choice will not bring you any benefits in the long run!
source share