mirror of
https://github.com/pestphp/pest.git
synced 2026-12-06 15:52:16 +01:00
fix(sharding): prevent shard filters from matching classes outside their partition (#1884)
* fix(sharding): prevent shard filters from matching classes outside their partition * lint * test: update snapshots for the shard filter boundary cases
This commit is contained in:
@@ -1839,6 +1839,9 @@
|
||||
✓ buildFilterArgument → it returns empty string for empty test list
|
||||
✓ buildFilterArgument → it generates compact filter for deeply nested namespaces
|
||||
✓ buildFilterArgument → it handles mix of nested and flat namespaces
|
||||
✓ 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
|
||||
✓ ensureFilterLengthIsSafe → it accepts filter within length limit
|
||||
✓ ensureFilterLengthIsSafe → it throws exception when filter exceeds default limit
|
||||
✓ ensureFilterLengthIsSafe → it respects custom limit from environment variable
|
||||
@@ -2259,4 +2262,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, 1600 passed (3489 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1603 passed (3495 assertions)
|
||||
@@ -60,7 +60,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 +75,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 +90,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 +118,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 +138,46 @@ 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 {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
$reflection = new ReflectionClass($shard);
|
||||
$method = $reflection->getMethod('buildFilterArgument');
|
||||
|
||||
$filter = $method->invoke($shard, ['Tests\\Feature\\After']);
|
||||
|
||||
expect(preg_match('{'.$filter.'}i', 'P\Tests\Feature\AfterAll::deletes file after all'))->toBe(0)
|
||||
->and('P\Tests\Feature\After::it runs')->toMatch('{'.$filter.'}i');
|
||||
});
|
||||
|
||||
it('still matches dataset variants after the class boundary', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
$reflection = new ReflectionClass($shard);
|
||||
$method = $reflection->getMethod('buildFilterArgument');
|
||||
|
||||
$filter = $method->invoke($shard, ['Tests\\Feature\\After']);
|
||||
|
||||
expect('P\Tests\Feature\After::it runs with data set "foo"')->toMatch('{'.$filter.'}i');
|
||||
});
|
||||
|
||||
it('keeps a class matchable when another class nests below its namespace', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
$reflection = new ReflectionClass($shard);
|
||||
$method = $reflection->getMethod('buildFilterArgument');
|
||||
|
||||
$filter = $method->invoke($shard, ['Tests\\Unit\\After', 'Tests\\Unit\\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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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, 1581 passed (3431 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1584 passed (3437 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
|
||||
Reference in New Issue
Block a user