phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

assertEqualsCanonicalizing() doesn't compare keys

Open joachim-n opened this issue 3 years ago • 1 comments

Q A
PHPUnit version 9.5.20
PHP version 7.4
Installation Method Composer

Summary

The following assertion passes:

$this->assertEqualsCanonicalizing(['a' => 3], ['b' => 3]);

The docs for this assertion at https://docs.phpunit.de/en/9.6/assertions.html#assertequalscanonicalizing don't mention associative arrays explicitly, but they don't say that assertEqualsCanonicalizing() is only intended for indexed arrays.

Current behavior

The assertion passes / the docs are incorrect.

How to reproduce

Expected behavior

I would say that the assertion should fail. But if it's by design that it passes, the docs need to mention this.

joachim-n avatar Jul 18 '22 09:07 joachim-n

Honestly, this bug plus the lack of another function like assertArraysIdentical() seems a major hole to me... I'm now stuck between writing my own function taking into account keys (an hour lost), investigating the code for assertEquals() to check if on arrays it will do canonicalization, recursion AND check key names (an hour lost), or including a different testing library (a bit less time lost, but code bloat). :(

Nevertheless, thank you so much for writing and maintaining PHPUnit!

janzankowski avatar Apr 06 '23 09:04 janzankowski