Skip to content

Commit fc52a09

Browse files
Closes #6142
1 parent 4d32a2c commit fc52a09

File tree

6 files changed

+72
-16
lines changed

6 files changed

+72
-16
lines changed

ChangeLog-11.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 11.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [11.5.11] - 2025-MM-DD
6+
7+
### Fixed
8+
9+
* [#6142](https://github.com/sebastianbergmann/phpunit/issues/6142): `$expected` and `$actual` are mixed up in failure description when `assertJsonFileEqualsJsonFile()` fails
10+
511
## [11.5.10] - 2025-02-25
612

713
### Fixed
@@ -117,6 +123,7 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
117123
* [#6055](https://github.com/sebastianbergmann/phpunit/issues/6055): `assertNotContainsOnly()` (use `assertContainsNotOnlyArray()`, `assertContainsNotOnlyBool()`, `assertContainsNotOnlyCallable()`, `assertContainsNotOnlyFloat()`, `assertContainsNotOnlyInt()`, `assertContainsNotOnlyIterable()`, `assertContainsNotOnlyNumeric()`, `assertContainsNotOnlyObject()`, `assertContainsNotOnlyResource()`, `assertContainsNotOnlyClosedResource()`, `assertContainsNotOnlyScalar()`, or `assertContainsNotOnlyString()` instead)
118124
* [#6059](https://github.com/sebastianbergmann/phpunit/issues/6059): `containsOnly()` (use `containsOnlyArray()`, `containsOnlyBool()`, `containsOnlyCallable()`, `containsOnlyFloat()`, `containsOnlyInt()`, `containsOnlyIterable()`, `containsOnlyNumeric()`, `containsOnlyObject()`, `containsOnlyResource()`, `containsOnlyClosedResource()`, `containsOnlyScalar()`, or `containsOnlyString()` instead)
119125

126+
[11.5.11]: https://github.com/sebastianbergmann/phpunit/compare/11.5.10...11.5
120127
[11.5.10]: https://github.com/sebastianbergmann/phpunit/compare/11.5.9...11.5.10
121128
[11.5.9]: https://github.com/sebastianbergmann/phpunit/compare/11.5.8...11.5.9
122129
[11.5.8]: https://github.com/sebastianbergmann/phpunit/compare/11.5.7...11.5.8

src/Framework/Assert.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,14 +2652,7 @@ final public static function assertJsonFileEqualsJsonFile(string $expectedFile,
26522652
self::assertIsString($actualJson);
26532653
self::assertJson($actualJson, $message);
26542654

2655-
$constraintExpected = new JsonMatches(
2656-
$expectedJson,
2657-
);
2658-
2659-
$constraintActual = new JsonMatches($actualJson);
2660-
2661-
self::assertThat($expectedJson, $constraintActual, $message);
2662-
self::assertThat($actualJson, $constraintExpected, $message);
2655+
self::assertThat($actualJson, new JsonMatches($expectedJson), $message);
26632656
}
26642657

26652658
/**
@@ -2683,14 +2676,7 @@ final public static function assertJsonFileNotEqualsJsonFile(string $expectedFil
26832676
self::assertIsString($actualJson);
26842677
self::assertJson($actualJson, $message);
26852678

2686-
$constraintExpected = new JsonMatches(
2687-
$expectedJson,
2688-
);
2689-
2690-
$constraintActual = new JsonMatches($actualJson);
2691-
2692-
self::assertThat($expectedJson, new LogicalNot($constraintActual), $message);
2693-
self::assertThat($actualJson, new LogicalNot($constraintExpected), $message);
2679+
self::assertThat($actualJson, LogicalNot(new JsonMatches($expectedJson)), $message);
26942680
}
26952681

26962682
/**

tests/end-to-end/regression/6142.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6142
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/6142/Issue6142Test.php';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
17+
F 1 / 1 (100%)
18+
19+
Time: %s, Memory: %s
20+
21+
There was 1 failure:
22+
23+
1) PHPUnit\TestFixture\Issue6142\Issue6142Test::testOne
24+
Failed asserting that '{"key": false}\n
25+
' matches JSON string "{"key": true}
26+
".
27+
--- Expected
28+
+++ Actual
29+
@@ @@
30+
{
31+
- "key": true
32+
+ "key": false
33+
}
34+
35+
%sIssue6142Test.php:%d
36+
37+
FAILURES!
38+
Tests: 1, Assertions: 7, Failures: 1.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Issue6142;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class Issue6142Test extends TestCase
15+
{
16+
public function testOne(): void
17+
{
18+
$expected = __DIR__ . '/expected.json';
19+
$actual = __DIR__ . '/actual.json';
20+
21+
$this->assertJsonFileEqualsJsonFile($expected, $actual);
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"key": false}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"key": true}

0 commit comments

Comments
 (0)