Skip to content

Commit fc53696

Browse files
Merge branch '10.5' into 11.5
* 10.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 7b508fa + 5bbaa6f commit fc53696

File tree

62 files changed

+1550
-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.

62 files changed

+1550
-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;
@@ -77,16 +78,6 @@ final class TestSuiteSorter
7778
private array $defectSortOrder = [];
7879
private readonly ResultCache $cache;
7980

80-
/**
81-
* @var array<string> A list of normalized names of tests before reordering
82-
*/
83-
private array $originalExecutionOrder = [];
84-
85-
/**
86-
* @var array<string> A list of normalized names of tests affected by reordering
87-
*/
88-
private array $executionOrder = [];
89-
9081
public function __construct(?ResultCache $cache = null)
9182
{
9283
$this->cache = $cache ?? new NullResultCache;
@@ -95,7 +86,7 @@ public function __construct(?ResultCache $cache = null)
9586
/**
9687
* @throws Exception
9788
*/
98-
public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDependencies, int $orderDefects, bool $isRootTestSuite = true): void
89+
public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDependencies, int $orderDefects): void
9990
{
10091
$allowedOrders = [
10192
self::ORDER_DEFAULT,
@@ -106,7 +97,9 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend
10697
];
10798

10899
if (!in_array($order, $allowedOrders, true)) {
100+
// @codeCoverageIgnoreStart
109101
throw new InvalidOrderException;
102+
// @codeCoverageIgnoreEnd
110103
}
111104

112105
$allowedOrderDefects = [
@@ -115,16 +108,14 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend
115108
];
116109

117110
if (!in_array($orderDefects, $allowedOrderDefects, true)) {
111+
// @codeCoverageIgnoreStart
118112
throw new InvalidOrderException;
119-
}
120-
121-
if ($isRootTestSuite) {
122-
$this->originalExecutionOrder = $this->calculateTestExecutionOrder($suite);
113+
// @codeCoverageIgnoreEnd
123114
}
124115

125116
if ($suite instanceof TestSuite) {
126117
foreach ($suite as $_suite) {
127-
$this->reorderTestsInSuite($_suite, $order, $resolveDependencies, $orderDefects, false);
118+
$this->reorderTestsInSuite($_suite, $order, $resolveDependencies, $orderDefects);
128119
}
129120

130121
if ($orderDefects === self::ORDER_DEFECTS_FIRST) {
@@ -133,26 +124,6 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend
133124

134125
$this->sort($suite, $order, $resolveDependencies, $orderDefects);
135126
}
136-
137-
if ($isRootTestSuite) {
138-
$this->executionOrder = $this->calculateTestExecutionOrder($suite);
139-
}
140-
}
141-
142-
/**
143-
* @return array<string>
144-
*/
145-
public function getOriginalExecutionOrder(): array
146-
{
147-
return $this->originalExecutionOrder;
148-
}
149-
150-
/**
151-
* @return array<string>
152-
*/
153-
public function getExecutionOrder(): array
154-
{
155-
return $this->executionOrder;
156127
}
157128

158129
private function sort(TestSuite $suite, int $order, bool $resolveDependencies, int $orderDefects): void
@@ -280,9 +251,8 @@ private function sortBySize(array $tests): array
280251
*/
281252
private function cmpDefectPriorityAndTime(Test $a, Test $b): int
282253
{
283-
if (!($a instanceof Reorderable && $b instanceof Reorderable)) {
284-
return 0;
285-
}
254+
assert($a instanceof Reorderable);
255+
assert($b instanceof Reorderable);
286256

287257
$priorityA = $this->defectSortOrder[$a->sortId()] ?? 0;
288258
$priorityB = $this->defectSortOrder[$b->sortId()] ?? 0;
@@ -360,24 +330,4 @@ private function resolveDependencies(array $tests): array
360330

361331
return array_merge($newTestOrder, $tests);
362332
}
363-
364-
/**
365-
* @return array<string>
366-
*/
367-
private function calculateTestExecutionOrder(Test $suite): array
368-
{
369-
$tests = [];
370-
371-
if ($suite instanceof TestSuite) {
372-
foreach ($suite->tests() as $test) {
373-
if (!$test instanceof TestSuite && $test instanceof Reorderable) {
374-
$tests[] = $test->sortId();
375-
} else {
376-
$tests = array_merge($tests, $this->calculateTestExecutionOrder($test));
377-
}
378-
}
379-
}
380-
381-
return $tests;
382-
}
383333
}

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)