Skip to content

Commit c30bcb1

Browse files
Merge branch '11.5' into 12.4
* 11.5: Add tests for randomized execution order Add test for empty test suite Ignore unhappy paths that will become obsolete after refactoring to enumeration (for $order parameter) and boolean (for $orderDefects parameter) We should be able to assume that every Test is also a Reorderable Add tests for ordering tests by duration Fix CS/WS issues Initial work on new end-to-end tests for test suite sorting Delete code that was only used by tests in PHPUnit's own test suite (but still run twice for the entire test suite for each test suite that is run) Delete existing tests for test reordering
2 parents 9253ec7 + fc53696 commit c30bcb1

File tree

59 files changed

+1433
-1422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1433
-1422
lines changed

src/Runner/TestSuiteSorter.php

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function array_merge;
1414
use function array_reverse;
1515
use function array_splice;
16+
use function assert;
1617
use function count;
1718
use function in_array;
1819
use function max;
@@ -57,16 +58,6 @@ final class TestSuiteSorter
5758
private array $defectSortOrder = [];
5859
private readonly ResultCache $cache;
5960

60-
/**
61-
* @var array<string> A list of normalized names of tests before reordering
62-
*/
63-
private array $originalExecutionOrder = [];
64-
65-
/**
66-
* @var array<string> A list of normalized names of tests affected by reordering
67-
*/
68-
private array $executionOrder = [];
69-
7061
public function __construct(?ResultCache $cache = null)
7162
{
7263
$this->cache = $cache ?? new NullResultCache;
@@ -75,7 +66,7 @@ public function __construct(?ResultCache $cache = null)
7566
/**
7667
* @throws Exception
7768
*/
78-
public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDependencies, int $orderDefects, bool $isRootTestSuite = true): void
69+
public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDependencies, int $orderDefects): void
7970
{
8071
$allowedOrders = [
8172
self::ORDER_DEFAULT,
@@ -86,7 +77,9 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend
8677
];
8778

8879
if (!in_array($order, $allowedOrders, true)) {
80+
// @codeCoverageIgnoreStart
8981
throw new InvalidOrderException;
82+
// @codeCoverageIgnoreEnd
9083
}
9184

9285
$allowedOrderDefects = [
@@ -95,16 +88,14 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend
9588
];
9689

9790
if (!in_array($orderDefects, $allowedOrderDefects, true)) {
91+
// @codeCoverageIgnoreStart
9892
throw new InvalidOrderException;
99-
}
100-
101-
if ($isRootTestSuite) {
102-
$this->originalExecutionOrder = $this->calculateTestExecutionOrder($suite);
93+
// @codeCoverageIgnoreEnd
10394
}
10495

10596
if ($suite instanceof TestSuite) {
10697
foreach ($suite as $_suite) {
107-
$this->reorderTestsInSuite($_suite, $order, $resolveDependencies, $orderDefects, false);
98+
$this->reorderTestsInSuite($_suite, $order, $resolveDependencies, $orderDefects);
10899
}
109100

110101
if ($orderDefects === self::ORDER_DEFECTS_FIRST) {
@@ -113,26 +104,6 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend
113104

114105
$this->sort($suite, $order, $resolveDependencies, $orderDefects);
115106
}
116-
117-
if ($isRootTestSuite) {
118-
$this->executionOrder = $this->calculateTestExecutionOrder($suite);
119-
}
120-
}
121-
122-
/**
123-
* @return array<string>
124-
*/
125-
public function getOriginalExecutionOrder(): array
126-
{
127-
return $this->originalExecutionOrder;
128-
}
129-
130-
/**
131-
* @return array<string>
132-
*/
133-
public function getExecutionOrder(): array
134-
{
135-
return $this->executionOrder;
136107
}
137108

138109
private function sort(TestSuite $suite, int $order, bool $resolveDependencies, int $orderDefects): void
@@ -260,9 +231,8 @@ private function sortBySize(array $tests): array
260231
*/
261232
private function cmpDefectPriorityAndTime(Test $a, Test $b): int
262233
{
263-
if (!($a instanceof Reorderable && $b instanceof Reorderable)) {
264-
return 0;
265-
}
234+
assert($a instanceof Reorderable);
235+
assert($b instanceof Reorderable);
266236

267237
$priorityA = $this->defectSortOrder[$a->sortId()] ?? 0;
268238
$priorityB = $this->defectSortOrder[$b->sortId()] ?? 0;
@@ -340,24 +310,4 @@ private function resolveDependencies(array $tests): array
340310

341311
return array_merge($newTestOrder, $tests);
342312
}
343-
344-
/**
345-
* @return array<string>
346-
*/
347-
private function calculateTestExecutionOrder(Test $suite): array
348-
{
349-
$tests = [];
350-
351-
if ($suite instanceof TestSuite) {
352-
foreach ($suite->tests() as $test) {
353-
if (!$test instanceof TestSuite && $test instanceof Reorderable) {
354-
$tests[] = $test->sortId();
355-
} else {
356-
$tests = array_merge($tests, $this->calculateTestExecutionOrder($test));
357-
}
358-
}
359-
}
360-
361-
return $tests;
362-
}
363313
}

tests/end-to-end/execution-order/_files/ClonedDependencyTest.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

tests/end-to-end/execution-order/_files/MultiDependencyTest_result_cache.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/end-to-end/execution-order/_files/StackTest.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/end-to-end/execution-order/_files/TestWithDifferentDurations.phpunit.result.cache.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/end-to-end/execution-order/_files/order-by-duration.phpunit.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/end-to-end/execution-order/cache-result.phpt

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/end-to-end/execution-order/dependencies-clone.phpt

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/end-to-end/execution-order/dependencies-isolation.phpt

Lines changed: 0 additions & 54 deletions
This file was deleted.

tests/end-to-end/execution-order/depends-as-parameter-with-isolation.phpt

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)