From a8676db992a244667abd0cad8add81c152318675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=C4=87?= <70343669+tomiichx@users.noreply.github.com> Date: Wed, 29 Jul 2026 12:24:24 +0200 Subject: [PATCH] fix(overrides): updates test suite sorter for phpunit 13 orders --- overrides/Runner/TestSuiteSorter.php | 50 ++++++++++++++++++++++++---- tests/Features/OrderBy.php | 29 ++++++++++++++++ 2 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 tests/Features/OrderBy.php diff --git a/overrides/Runner/TestSuiteSorter.php b/overrides/Runner/TestSuiteSorter.php index 13b8642f3..61b1e485d 100644 --- a/overrides/Runner/TestSuiteSorter.php +++ b/overrides/Runner/TestSuiteSorter.php @@ -78,9 +78,13 @@ final class TestSuiteSorter public const int ORDER_DEFECTS_FIRST = 3; - public const int ORDER_DURATION = 4; + public const int ORDER_DURATION_ASCENDING = 4; - public const int ORDER_SIZE = 5; + public const int ORDER_SIZE_ASCENDING = 5; + + public const int ORDER_DURATION_DESCENDING = 6; + + public const int ORDER_SIZE_DESCENDING = 7; /** * @var non-empty-array @@ -113,8 +117,10 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend self::ORDER_DEFAULT, self::ORDER_REVERSED, self::ORDER_RANDOMIZED, - self::ORDER_DURATION, - self::ORDER_SIZE, + self::ORDER_DURATION_ASCENDING, + self::ORDER_SIZE_ASCENDING, + self::ORDER_DURATION_DESCENDING, + self::ORDER_SIZE_DESCENDING, ]; if (! in_array($order, $allowedOrders, true)) { @@ -157,10 +163,14 @@ private function sort(TestSuite $suite, int $order, bool $resolveDependencies, i $suite->setTests($this->reverse($suite->tests())); } elseif ($order === self::ORDER_RANDOMIZED) { $suite->setTests($this->randomize($suite->tests())); - } elseif ($order === self::ORDER_DURATION) { + } elseif ($order === self::ORDER_DURATION_ASCENDING) { $suite->setTests($this->sortByDuration($suite->tests())); - } elseif ($order === self::ORDER_SIZE) { + } elseif ($order === self::ORDER_DURATION_DESCENDING) { + $suite->setTests($this->sortByDurationDescending($suite->tests())); + } elseif ($order === self::ORDER_SIZE_ASCENDING) { $suite->setTests($this->sortBySize($suite->tests())); + } elseif ($order === self::ORDER_SIZE_DESCENDING) { + $suite->setTests($this->sortBySizeDescending($suite->tests())); } if ($orderDefects === self::ORDER_DEFECTS_FIRST) { @@ -242,6 +252,20 @@ private function sortByDuration(array $tests): array return $tests; } + /** + * @param list $tests + * @return list + */ + private function sortByDurationDescending(array $tests): array + { + usort( + $tests, + fn (Test $left, Test $right) => $this->cmpDuration($right, $left), + ); + + return $tests; + } + /** * @param list $tests * @return list @@ -256,6 +280,20 @@ private function sortBySize(array $tests): array return $tests; } + /** + * @param list $tests + * @return list + */ + private function sortBySizeDescending(array $tests): array + { + usort( + $tests, + fn (Test $left, Test $right) => $this->cmpSize($right, $left), + ); + + return $tests; + } + /** * Comparator callback function to sort tests for "reach failure as fast as possible". * diff --git a/tests/Features/OrderBy.php b/tests/Features/OrderBy.php new file mode 100644 index 000000000..f31297d52 --- /dev/null +++ b/tests/Features/OrderBy.php @@ -0,0 +1,29 @@ + 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], + ); + + $process->run(); + + expect($process->getExitCode())->toBe(0) + ->and(removeAnsiEscapeSequences($process->getOutput()))->toContain('1 passed'); +})->with([ + 'default', + 'defects', + 'duration', + 'duration-ascending', + 'duration-descending', + 'random', + 'reverse', + 'size', + 'size-ascending', + 'size-descending', +]);