Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertEqualsCanonicalizing() doesn't compare keys #5019

Closed
joachim-n opened this issue Jul 18, 2022 · 4 comments
Closed

assertEqualsCanonicalizing() doesn't compare keys #5019

joachim-n opened this issue Jul 18, 2022 · 4 comments
Labels
type/bug Something is broken

Comments

@joachim-n
Copy link

joachim-n commented Jul 18, 2022

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 joachim-n added the type/bug Something is broken label Jul 18, 2022
@janzankowski
Copy link

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!

@kubawerlos
Copy link
Contributor

This seems not to be an issue in PHPUnit 10 anymore, the assertion from report:

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

results now with:

There was 1 failure:

1) Test::testFoo
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    'a' => 3
+    'b' => 3
 )

@fmccown
Copy link

fmccown commented Nov 9, 2024

The issue appears to be back in PHPUnit 11.1.1 (using PHP 8.2.1).

@sebastianbergmann
Copy link
Owner

The issue appears to be back in PHPUnit 11.1.1 (using PHP 8.2.1).

Please see #5967.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

5 participants