Skip to content

diff output for assertEqualsCanonicalizing() is affected by order #5955

Open
@joachim-n

Description

Q A
PHPUnit version 11.3.5
PHP version 8.3.8
Installation Method Composer

Summary

The diff output when assertEqualsCanonicalizing() fails is affected by the order of the arrays.

Current behavior

Consider this assertion:

    $this->assertEqualsCanonicalizing(
      [
        "alpha",
        "beta",
      ],
      [
        "alpha",
        "beta",
        "gamma",
      ],
    );

the output is:

--- Expected
+++ Actual
@@ @@
 Array (
     0 => 'alpha'
     1 => 'beta'
+    2 => 'gamma'
 )

but with this assertion:

    $this->assertEqualsCanonicalizing(
      [
        "alpha",
        "gamma",
      ],
      [
        "alpha",
        "beta",
        "gamma",
      ],
    );

The output is:

--- Expected
+++ Actual
@@ @@
 Array (
     0 => 'alpha'
-    1 => 'gamma'
+    1 => 'beta'
+    2 => 'gamma'
 )

In both cases, there is one item extra item the actual value compared to the expected value, but in one case the diff shows that very clearly, and in the other case, the diff has extra noise.

How to reproduce

Expected behavior

Only 'beta' is surplus, so the output should be:

--- Expected
+++ Actual
@@ @@
 Array (
+    1 => 'beta'
 )

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions