Skip to content

fix(overrides): updates test suite sorter for phpunit 13 orders - #1784

Open
tomiichx wants to merge 1 commit into
pestphp:5.xfrom
tomiichx:fix/order-by-duration-and-size
Open

fix(overrides): updates test suite sorter for phpunit 13 orders#1784
tomiichx wants to merge 1 commit into
pestphp:5.xfrom
tomiichx:fix/order-by-duration-and-size

Conversation

@tomiichx

Copy link
Copy Markdown

What:

  • Bug Fix
  • New Feature

Description:

On Pest 5, four --order-by values crash at CLI-parse time, before a single test runs:

$ vendor/bin/pest --order-by=duration
Undefined constant PHPUnit\Runner\TestSuiteSorter::ORDER_DURATION_ASCENDING
at vendor/phpunit/phpunit/src/TextUI/Configuration/Cli/Builder.php:768

Same failure for duration-ascending, duration-descending, and size-descending.
Reproduced on Pest 5.0.1, PHPUnit 13.2.4, PHP 8.4.23.

The cause is overrides/Runner/TestSuiteSorter.php, which BootOverrides loads in place
of PHPUnit's class. It still declares the PHPUnit 12 constants:

public const int ORDER_DURATION = 4;
public const int ORDER_SIZE     = 5;

PHPUnit 13 renamed both and added descending variants (src/Runner/TestSuiteSorter.php:38-45):

public const int ORDER_DURATION_ASCENDING  = 4;
public const int ORDER_SIZE_ASCENDING      = 5;
public const int ORDER_DURATION_DESCENDING = 6;
public const int ORDER_SIZE_DESCENDING     = 7;

Builder.php resolves the new names, the override does not define them, and PHP fails
on the constant lookup. Worth noting that the duration arm is also where PHPUnit emits
its "use duration-ascending instead" deprecation, so users never see that notice either.

--order-by=size happens to still work because ORDER_SIZE and ORDER_SIZE_ASCENDING
are both 5, but it resolves through a constant the override defines under the old name,
which is luck rather than correctness.

This PR updates the override to declare PHPUnit 13's four constants and extends the
$order comparisons in reorderTestsInSuite() so ascending and descending are handled
separately for both duration and size, matching PHPUnit 13's implementation. The old
ORDER_DURATION and ORDER_SIZE names are dropped rather than aliased, since keeping
them would let the override drift from PHPUnit again.

Anyone upgrading from Pest 4 with --order-by=duration in their config, which is common
for parallel suites, currently gets a hard crash that points into PHPUnit instead of Pest.

@tomiichx
tomiichx marked this pull request as draft July 29, 2026 10:32
@tomiichx
tomiichx force-pushed the fix/order-by-duration-and-size branch from f0e2a5f to a8676db Compare July 29, 2026 10:38
@tomiichx
tomiichx marked this pull request as ready for review July 29, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant