From 8e3f467d8a7d0a6f8a2387309d752474b3fa6875 Mon Sep 17 00:00:00 2001 From: Mikko <51752497+apael@users.noreply.github.com> Date: Fri, 13 Nov 2026 16:06:20 +0200 Subject: [PATCH] fix(sharding): strip `--runner` from the `--list-tests` sub-process (#2004) * fix(sharding): strip `--runner` from the `--list-tests` sub-process * fix(sharding): strip a space-separated `--runner` value too Co-Authored-By: Claude Opus 5.5 (1M context) * test: count the two new shard tests in the visual suite totals Co-Authored-By: Claude Opus 5.5 (1M context) --------- Co-authored-by: Apa Co-authored-by: Claude Opus 5.5 (1M context) --- src/Plugins/Shard.php | 33 ++++++++++++++++++++++++++----- tests/.snapshots/success.txt | 4 +++- tests/Unit/Plugins/Shard.php | 38 ++++++++++++++++++++++++++++++++++++ tests/Visual/Parallel.php | 2 +- 4 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/Plugins/Shard.php b/src/Plugins/Shard.php index c98376c8..b6551201 100644 --- a/src/Plugins/Shard.php +++ b/src/Plugins/Shard.php @@ -190,11 +190,34 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable */ private function removeParallelArguments(array $arguments): array { - return array_values(array_filter( - $arguments, - fn (string $argument): bool => ! in_array($argument, ['--parallel', '-p'], strict: true) - && ! str_starts_with($argument, '--processes'), - )); + $filtered = []; + $skipNext = false; + + foreach ($arguments as $argument) { + if ($skipNext) { + $skipNext = false; + + if (! str_starts_with($argument, '-')) { + continue; + } + } + + if ($argument === '--runner') { + $skipNext = true; + + continue; + } + + if (in_array($argument, ['--parallel', '-p'], strict: true) + || str_starts_with($argument, '--processes') + || str_starts_with($argument, '--runner=')) { + continue; + } + + $filtered[] = $argument; + } + + return $filtered; } /** diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index de896b1d..4ba69a1a 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1888,6 +1888,8 @@ ✓ buildListTestsCommand → it forwards --test-directory even when input arguments include one ✓ buildListTestsCommand → it strips --processes=N when building the list-tests command ✓ buildListTestsCommand → it strips --processes N (space-separated) when building the list-tests command + ✓ buildListTestsCommand → it strips --runner when building the list-tests command + ✓ buildListTestsCommand → it strips a space-separated --runner and its value when building the list-tests command ✓ addOutput → it displays shard information after test execution ✓ addOutput → it uses singular form for single test file ✓ addOutput → it returns original exit code when shard is not set @@ -2323,4 +2325,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1650 passed (3653 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1652 passed (3655 assertions) \ No newline at end of file diff --git a/tests/Unit/Plugins/Shard.php b/tests/Unit/Plugins/Shard.php index acdb9e7e..5e87f524 100644 --- a/tests/Unit/Plugins/Shard.php +++ b/tests/Unit/Plugins/Shard.php @@ -525,6 +525,44 @@ describe('buildListTestsCommand', function (): void { ->and($command)->toContain('--update-shards') ->and($command)->toContain('--test-directory=tests'); }); + + it('strips --runner when building the list-tests command', function (): void { + $output = new BufferedOutput; + $shard = new Shard($output); + + $reflection = new ReflectionClass($shard); + $method = $reflection->getMethod('buildListTestsCommand'); + + $command = $method->invoke($shard, ['artisan', 'test', '--runner=\\Illuminate\\Testing\\ParallelRunner', '--shard=1/3'], 'tests'); + + expect($command)->toBe([ + PHP_BINARY, + 'artisan', + 'test', + '--shard=1/3', + '--test-directory=tests', + '--list-tests', + ]); + }); + + it('strips a space-separated --runner and its value when building the list-tests command', function (): void { + $output = new BufferedOutput; + $shard = new Shard($output); + + $reflection = new ReflectionClass($shard); + $method = $reflection->getMethod('buildListTestsCommand'); + + $command = $method->invoke($shard, ['artisan', 'test', '--runner', '\\Illuminate\\Testing\\ParallelRunner', '--shard=1/3'], 'tests'); + + expect($command)->toBe([ + PHP_BINARY, + 'artisan', + 'test', + '--shard=1/3', + '--test-directory=tests', + '--list-tests', + ]); + }); }); describe('addOutput', function (): void { diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 3b591926..024728a6 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -20,7 +20,7 @@ test('parallel', function () use ($run): void { $output = $run('--exclude-group=integration'); $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1622 passed (3577 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1624 passed (3579 assertions)'; expect($output) ->toContain("Tests: {$expected}")