Skip to content

$expected and $actual are mixed up in failure description when assertJsonFileEqualsJsonFile() fails #6142

@sven-81

Description

@sven-81
Q A
PHPUnit version 12.0.5
PHP version 8.4.4
Installation Method Composer

Summary

If failing assertJsonFileEqualsJsonFile expected, actual are mixed up

Current behavior

If assertJsonFileEqualsJsonFile is failing, the output of expected, actual are mixed up.

How to reproduce

File expected.json:
{"key": true}

File actual.json:
{"key": false}

<?php
declare(strict_types=1);

use PHPUnit\Framework\TestCase;
class JsonTest extends TestCase
{
    public function testAssertJson(): void
    {
        $expected =__DIR__ . '/expected.json';
        $actual =__DIR__ . '/actual.json';

        $this->assertJsonFileEqualsJsonFile($expected, $actual);
    }
}
PHP 8.4.4 (cli) (built: Feb 25 2025 02:19:56) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.4, Copyright (c) Zend Technologies
    with Xdebug v3.4.1, Copyright (c) 2002-2025, by Derick Rethans

PHPUnit 12.0.5 by Sebastian Bergmann and contributors.
Runtime:       PHP 8.4.4

.F......                                                            8 / 8 (100%)

Time: 00:00.024, Memory: 12.00 MB

There was 1 failure:

1) placementDetermination\book\PageTest::testName
Failed asserting that '{\n
  "key": true\n
}' matches JSON string "{
  "key": false
}".
--- Expected
+++ Actual
@@ @@
 {
-    "key": false
+    "key": true
 }

Expected behavior

--- Expected
+++ Actual
@@ @@
 {
-    "key": true
+    "key": false
 }

Metadata

Metadata

Labels

feature/assertionIssues related to assertions and expectationstype/bugSomething is brokenversion/11Something affects PHPUnit 11version/12Something affects PHPUnit 12

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions