Compare commits

...

5 Commits

Author SHA1 Message Date
nuno maduro c947def97e release: 5.3.3 2026-10-18 12:51:10 +01:00
nuno maduro 3e5a2410b7 fix: phpunit classes not being inlcuded on sharding 2026-10-18 12:28:03 +01:00
Pushpak Chhajed e9fa0f50c5 perf: O(1) test method lookup 2026-10-16 22:20:38 +05:30
Pushpak Chhajed b6dddcc821 perf: stop spawning stty for every test when output is not a TTY 2026-10-16 22:20:30 +05:30
Muhammed Alkhudiry 3a5a14b6a6 fix: reduce parallel worker polling interval to 1 ms (#1967)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 22:19:33 +05:30
13 changed files with 95 additions and 43 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"
},
+11
View File
@@ -4,9 +4,11 @@ declare(strict_types=1);
namespace Pest\Bootstrappers;
use Closure;
use Pest\Contracts\Bootstrapper;
use Pest\Support\View;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Terminal;
/**
* @internal
@@ -22,5 +24,14 @@ final readonly class BootView implements Bootstrapper
public function boot(): void
{
View::renderUsing($this->output);
if (getenv('COLUMNS') === false && property_exists(Terminal::class, 'width') && property_exists(Terminal::class, 'height')) {
(new Terminal)->getWidth();
Closure::bind(static function (): void {
Terminal::$width ??= 0;
Terminal::$height ??= 0;
}, null, Terminal::class)();
}
}
}
+9 -22
View File
@@ -44,6 +44,11 @@ final class TestCaseFactory
*/
public array $methods = [];
/**
* @var array<string, TestCaseMethodFactory>
*/
private array $methodsByName = [];
/**
* @var array <int, class-string>
*/
@@ -208,35 +213,17 @@ final class TestCaseFactory
}
$this->methods[$method->description] = $method;
$this->methodsByName[Str::evaluable($method->description)] ??= $method;
}
public function hasMethod(string $methodName): bool
{
foreach ($this->methods as $method) {
if ($method->description === null) {
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
}
if ($methodName === Str::evaluable($method->description)) {
return true;
}
}
return false;
return isset($this->methodsByName[$methodName]);
}
public function getMethod(string $methodName): TestCaseMethodFactory
{
foreach ($this->methods as $method) {
if ($method->description === null) {
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
}
if ($methodName === Str::evaluable($method->description)) {
return $method;
}
}
throw ShouldNotHappen::fromMessage(sprintf('Method [%s] not found.', $methodName));
return $this->methodsByName[$methodName]
?? throw ShouldNotHappen::fromMessage(sprintf('Method [%s] not found.', $methodName));
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ namespace Pest;
function version(): string
{
return '5.3.2';
return '5.3.3';
}
function testDirectory(string $file = ''): string
+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
{
@@ -66,7 +66,7 @@ final class WrapperRunner implements RunnerInterface
{
public static ?TestResult $result = null;
private const int CYCLE_SLEEP = 10000;
private const int CYCLE_SLEEP = 1000;
private readonly ResultPrinter $printer;
+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);
@@ -1,5 +1,5 @@
Pest Testing Framework 5.3.2.
Pest Testing Framework 5.3.3.
USAGE: pest <file> [options]
@@ -1,3 +1,3 @@
Pest Testing Framework 5.3.2.
Pest Testing Framework 5.3.3.
+4 -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
@@ -2204,6 +2206,7 @@
✓ it does not allow to add the same test description twice
✓ it does not allow static closures
✓ it alerts users about tests with arguments but no input
✓ it can look up registered test methods by evaluable name
✓ it can return an array of all test suite filenames
PASS Tests\Visual\BeforeEachTestName
@@ -2262,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, 1603 passed (3495 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 {
+26
View File
@@ -1,6 +1,7 @@
<?php
use Pest\Exceptions\DatasetMissing;
use Pest\Exceptions\ShouldNotHappen;
use Pest\Exceptions\TestAlreadyExist;
use Pest\Exceptions\TestClosureMustNotBeStatic;
use Pest\Factories\TestCaseMethodFactory;
@@ -43,6 +44,31 @@ it('alerts users about tests with arguments but no input', function (): void {
sprintf('The test [%s] in [%s] expects [%d] argument(s) ([%s]), but no dataset was provided. Please chain [with()] onto the test to supply one.', 'bar', 'foo', 1, 'int $arg'),
);
it('can look up registered test methods by evaluable name', function (): void {
$testSuite = new TestSuite(getcwd(), 'tests');
$firstMethod = new TestCaseMethodFactory('foo', null);
$firstMethod->description = 'first test_with punctuation!';
$testSuite->tests->set($firstMethod);
$secondMethod = new TestCaseMethodFactory('foo', null);
$secondMethod->description = 'second test';
$testSuite->tests->set($secondMethod);
$collidingMethod = new TestCaseMethodFactory('foo', null);
$collidingMethod->description = 'second-test';
$testSuite->tests->set($collidingMethod);
$testCase = $testSuite->tests->get('foo');
expect($testCase->hasMethod('__pest_evaluable_first_test__with_punctuation_'))->toBeTrue()
->and($testCase->getMethod('__pest_evaluable_first_test__with_punctuation_'))->toBe($firstMethod)
->and($testCase->hasMethod('__pest_evaluable_second_test'))->toBeTrue()
->and($testCase->getMethod('__pest_evaluable_second_test'))->toBe($secondMethod)
->and($testCase->hasMethod('__pest_evaluable_missing'))->toBeFalse()
->and(fn () => $testCase->getMethod('__pest_evaluable_missing'))->toThrow(ShouldNotHappen::class, 'Method [__pest_evaluable_missing] not found.');
});
it('can return an array of all test suite filenames', function (): void {
$testSuite = new TestSuite(getcwd(), 'tests');
+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, 1584 passed (3437 assertions)';
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1587 passed (3447 assertions)';
expect($output)
->toContain("Tests: {$expected}")