Skip to content

Commit c3f41f6

Browse files
Closes #6588
1 parent b082aa4 commit c3f41f6

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

ChangeLog-13.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ All notable changes of the PHPUnit 13.2 release series are documented in this fi
2525
* [#6575](https://github.com/sebastianbergmann/phpunit/issues/6575): `--list-test-ids` CLI option and enhance `--filter` CLI option to support test ID syntax
2626
* [#6577](https://github.com/sebastianbergmann/phpunit/issues/6577): `--run-test-id <test-id>` CLI option that accepts a single test ID for exact matching
2727
* [#6579](https://github.com/sebastianbergmann/phpunit/pull/6579): Properly handle issues triggered outside of tests
28+
* [#6588](https://github.com/sebastianbergmann/phpunit/issues/6588): Canonicalize baseline
2829
* The `executionOrder` attribute in the XML configuration file now accepts `defects` combined with any main order, as well as three-way combinations of `depends`/`no-depends`, `defects`, and a main order (for example, `depends,defects,duration-ascending`)
2930

3031
### Changed

src/Runner/Baseline/Baseline.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
*/
1010
namespace PHPUnit\Runner\Baseline;
1111

12+
use function ksort;
13+
use function strcmp;
14+
use function usort;
15+
1216
/**
1317
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
1418
*
@@ -56,6 +60,21 @@ public function has(Issue $issue): bool
5660
*/
5761
public function groupedByFileAndLine(): array
5862
{
59-
return $this->issues;
63+
$issues = $this->issues;
64+
65+
ksort($issues);
66+
67+
foreach ($issues as &$lines) {
68+
ksort($lines);
69+
70+
foreach ($lines as &$issuesOnLine) {
71+
usort(
72+
$issuesOnLine,
73+
static fn (Issue $a, Issue $b): int => strcmp($a->description(), $b->description()),
74+
);
75+
}
76+
}
77+
78+
return $issues;
6079
}
6180
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
$x = $y;
11+
$y = $z;

tests/unit/Runner/Baseline/BaselineTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
namespace PHPUnit\Runner\Baseline;
1111

12+
use function array_keys;
1213
use function realpath;
1314
use PHPUnit\Framework\Attributes\CoversClass;
1415
use PHPUnit\Framework\Attributes\Group;
@@ -45,6 +46,27 @@ public function testGroupsIssuesByFileAndLine(): void
4546
$this->assertTrue($this->issue()->equals($line[0]));
4647
}
4748

49+
public function testCanonicalizesIssuesByFileLineAndDescription(): void
50+
{
51+
$fileA = realpath(__DIR__ . '/../../../_files/baseline/AnotherFileWithIssues.php');
52+
$fileB = realpath(__DIR__ . '/../../../_files/baseline/FileWithIssues.php');
53+
54+
$baseline = new Baseline;
55+
56+
$baseline->add(Issue::from($fileB, 11, null, 'Undefined variable $c'));
57+
$baseline->add(Issue::from($fileB, 10, null, 'b: Undefined variable $b'));
58+
$baseline->add(Issue::from($fileB, 10, null, 'a: Undefined variable $b'));
59+
$baseline->add(Issue::from($fileA, 10, null, 'Undefined variable $y'));
60+
61+
$issues = $baseline->groupedByFileAndLine();
62+
63+
$this->assertSame([$fileA, $fileB], array_keys($issues));
64+
$this->assertSame([10, 11], array_keys($issues[$fileB]));
65+
66+
$this->assertSame('a: Undefined variable $b', $issues[$fileB][10][0]->description());
67+
$this->assertSame('b: Undefined variable $b', $issues[$fileB][10][1]->description());
68+
}
69+
4870
public function testCanBeQueried(): void
4971
{
5072
$baseline = new Baseline;

0 commit comments

Comments
 (0)