fix: phpunit classes not being inlcuded on sharding

This commit is contained in:
nuno maduro
2026-10-18 12:28:03 +01:00
parent e9fa0f50c5
commit 3e5a2410b7
6 changed files with 44 additions and 17 deletions
+2 -2
View File
@@ -25,13 +25,13 @@
"pestphp/pest-plugin-arch": "^5.0.0",
"pestphp/pest-plugin-mutate": "^5.0.2",
"pestphp/pest-plugin-profanity": "^5.0.1",
"phpunit/phpunit": "^13.4.2",
"phpunit/phpunit": "^13.4.3",
"symfony/process": "^8.1.7"
},
"conflict": {
"filp/whoops": "<2.18.3",
"laravel/boost": "<2.6.0",
"phpunit/phpunit": ">13.4.2",
"phpunit/phpunit": ">13.4.3",
"sebastian/exporter": "<7.0.0",
"webmozart/assert": "<1.11.0"
},
+1 -1
View File
@@ -40,7 +40,7 @@ trait HandleArguments
/**
* @param array<int, string> $arguments
* @return array<int, string>
* @return list<string>
*/
public function popArgument(string $argument, array $arguments): array
{
+3 -6
View File
@@ -87,8 +87,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
return $arguments;
}
// @phpstan-ignore-next-line
$input = new ArgvInput($arguments);
$input = new ArgvInput(array_values($arguments));
['index' => $index, 'total' => $total] = self::getShard($input);
@@ -97,7 +96,6 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
$arguments,
)));
/** @phpstan-ignore-next-line */
$tests = $this->allTests($arguments);
$timings = $this->loadShardsFile();
@@ -157,7 +155,6 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
self::$updateShards = true;
/** @phpstan-ignore-next-line */
self::$knownTests = $this->allTests($arguments);
if ($this->hasArgument('--parallel', $arguments) || $this->hasArgument('-p', $arguments)) {
@@ -262,12 +259,12 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
}
if ($endsWithClass && $subRegex !== '') {
$parts[] = '(?:'.preg_quote($key, '/').'(?=::)|'.$segment.')';
$parts[] = '(?:'.preg_quote($key, '/').'::|'.$segment.')';
continue;
}
$parts[] = $endsWithClass ? $segment.'(?=::)' : $segment;
$parts[] = $endsWithClass ? $segment.'::' : $segment;
}
return implode('|', $parts);
+3 -1
View File
@@ -1842,6 +1842,8 @@
✓ buildFilterArgument → it does not match a class outside of the shard when another class name is its prefix
✓ buildFilterArgument → it still matches dataset variants after the class boundary
✓ buildFilterArgument → it keeps a class matchable when another class nests below its namespace
✓ buildFilterArgument → it keeps the filter whole when the parallel runner passes it as --filter=VALUE
✓ buildFilterArgument → it matches a class-based test of the shard
✓ ensureFilterLengthIsSafe → it accepts filter within length limit
✓ ensureFilterLengthIsSafe → it throws exception when filter exceeds default limit
✓ ensureFilterLengthIsSafe → it respects custom limit from environment variable
@@ -2263,4 +2265,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, 35 skipped, 1604 passed (3502 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1606 passed (3505 assertions)
+34 -6
View File
@@ -2,6 +2,7 @@
use Pest\Exceptions\InvalidOption;
use Pest\Plugins\Shard;
use SebastianBergmann\CliParser\Parser;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\BufferedOutput;
@@ -60,7 +61,7 @@ describe('buildFilterArgument', function (): void {
$filter = $method->invoke($shard, ['Tests\\Unit\\ExampleTest']);
expect($filter)->toBe('Tests\\\\Unit\\\\ExampleTest(?=::)');
expect($filter)->toBe('Tests\\\\Unit\\\\ExampleTest::');
});
it('generates compact filter for multiple tests with common prefix', function (): void {
@@ -75,7 +76,7 @@ describe('buildFilterArgument', function (): void {
'Tests\\Unit\\Foo\\BazTest',
]);
expect($filter)->toBe('Tests\\\\Unit\\\\Foo\\\\(BarTest(?=::)|BazTest(?=::))');
expect($filter)->toBe('Tests\\\\Unit\\\\Foo\\\\(BarTest::|BazTest::)');
});
it('generates compact filter for tests with different namespaces', function (): void {
@@ -90,7 +91,7 @@ describe('buildFilterArgument', function (): void {
'Tests\\Feature\\BarTest',
]);
expect($filter)->toBe('Tests\\\\(Unit\\\\FooTest(?=::)|Feature\\\\BarTest(?=::))');
expect($filter)->toBe('Tests\\\\(Unit\\\\FooTest::|Feature\\\\BarTest::)');
});
it('returns empty string for empty test list', function (): void {
@@ -118,7 +119,7 @@ describe('buildFilterArgument', function (): void {
'Tests\\Unit\\Plugins\\Concerns\\Baz',
]);
expect($filter)->toBe('Tests\\\\Unit\\\\Plugins\\\\Concerns\\\\(Foo(?=::)|Bar(?=::)|Baz(?=::))');
expect($filter)->toBe('Tests\\\\Unit\\\\Plugins\\\\Concerns\\\\(Foo::|Bar::|Baz::)');
});
it('handles mix of nested and flat namespaces', function (): void {
@@ -138,7 +139,7 @@ describe('buildFilterArgument', function (): void {
$filter = $method->invoke($shard, $tests);
expect($filter)
->toBe(addslashes('Tests\\Unit\\(SimpleTest(?=::)|Plugins\\Concerns\\(HandleArguments(?=::)|Validation(?=::))|Another\\Deep\\Nested\\Test(?=::))'));
->toBe(addslashes('Tests\\Unit\\(SimpleTest::|Plugins\\Concerns\\(HandleArguments::|Validation::)|Another\\Deep\\Nested\\Test::)'));
});
it('does not match a class outside of the shard when another class name is its prefix', function (): void {
@@ -175,10 +176,37 @@ describe('buildFilterArgument', function (): void {
$filter = $method->invoke($shard, ['Tests\\Unit\\After', 'Tests\\Unit\\After\\AfterAll']);
expect($filter)->toBe('Tests\\\\Unit\\\\(?:After(?=::)|After\\\\AfterAll(?=::))')
expect($filter)->toBe('Tests\\\\Unit\\\\(?:After::|After\\\\AfterAll::)')
->and('P\Tests\Unit\After::x')->toMatch('{'.$filter.'}i')
->and('P\Tests\Unit\After\AfterAll::y')->toMatch('{'.$filter.'}i');
});
it('keeps the filter whole when the parallel runner passes it as --filter=VALUE', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
$reflection = new ReflectionClass($shard);
$method = $reflection->getMethod('buildFilterArgument');
$filter = $method->invoke($shard, ['Tests\\Unit\\AlphaTest', 'Tests\\Unit\\After', 'Tests\\Unit\\After\\AfterAll']);
[$options] = new Parser()->parse(['--filter='.$filter], '', ['filter=']);
expect($options)->toBe([['--filter', $filter]]);
});
it('matches a class-based test of the shard', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
$reflection = new ReflectionClass($shard);
$method = $reflection->getMethod('buildFilterArgument');
$filter = $method->invoke($shard, ['Tests\\Unit\\AlphaTest']);
expect('Tests\Unit\AlphaTest::test_it_runs')->toMatch('{'.$filter.'}i')
->and('Tests\Unit\AlphaTestTwo::test_it_runs')->not->toMatch('{'.$filter.'}i');
});
});
describe('ensureFilterLengthIsSafe', function (): void {
+1 -1
View File
@@ -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, 27 skipped, 1585 passed (3444 assertions)';
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1587 passed (3447 assertions)';
expect($output)
->toContain("Tests: {$expected}")