assertEqualsCanonicalizing() doesn't compare keys
| 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.
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!