Fix parallel file selection and empty-suite reporting

This commit is contained in:
Aleksandr Štšepelin
2026-03-25 23:59:28 +02:00
parent e6ab897594
commit 07737bc0b2
5 changed files with 151 additions and 10 deletions

View File

@ -1757,6 +1757,9 @@
✓ parallel
✓ a parallel test can extend another test with same name
PASS Tests\Visual\ParallelNestedDatasets
✓ parallel reports missing nested datasets without a passing summary
PASS Tests\Visual\SingleTestOrDirectory
✓ allows to run a single test
✓ allows to run a directory
@ -1782,4 +1785,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, 39 todos, 35 skipped, 1188 passed (2813 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 35 skipped, 1189 passed (2819 assertions)

View File

@ -21,5 +21,5 @@ test('parallel', function () use ($run) {
})->skipOnWindows();
test('a parallel test can extend another test with same name', function () use ($run) {
expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 2 passed (2 assertions)');
expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 1 passed (1 assertions)');
});

View File

@ -0,0 +1,91 @@
<?php
use Symfony\Component\Process\Process;
$fixture = function (): array {
$directory = dirname(__DIR__).DIRECTORY_SEPARATOR.'Features'.DIRECTORY_SEPARATOR.'ParallelNestedDatasetRepro';
$datasetsDirectory = $directory.DIRECTORY_SEPARATOR.'Datasets'.DIRECTORY_SEPARATOR.'Nested';
$target = $directory.DIRECTORY_SEPARATOR.'TestFileWithNestedDataset.php';
if (! is_dir($datasetsDirectory)) {
mkdir($datasetsDirectory, 0777, true);
}
file_put_contents($datasetsDirectory.DIRECTORY_SEPARATOR.'Users.php', <<<'PHP'
<?php
dataset('nested.users', [
['alice'],
['bob'],
]);
PHP);
file_put_contents($target, <<<'PHP'
<?php
test('loads nested dataset', function (string $name) {
expect($name)->not->toBeEmpty();
})->with('nested.users');
PHP);
return [$directory, 'tests/Features/ParallelNestedDatasetRepro/TestFileWithNestedDataset.php'];
};
$cleanup = function (string $directory): void {
if (! is_dir($directory)) {
return;
}
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST,
);
foreach ($iterator as $item) {
if ($item->isDir()) {
rmdir($item->getPathname());
} else {
unlink($item->getPathname());
}
}
rmdir($directory);
};
$run = function (string $target, bool $parallel = false): array {
$command = ['php', 'bin/pest', $target, '--colors=never'];
if ($parallel) {
$command[] = '--parallel';
$command[] = '--processes=2';
}
$process = new Process($command, dirname(__DIR__, 2),
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'],
);
$process->run();
return [
'exitCode' => $process->getExitCode(),
'output' => removeAnsiEscapeSequences($process->getOutput().$process->getErrorOutput()),
];
};
test('parallel reports missing nested datasets without a passing summary', function () use ($cleanup, $fixture, $run) {
[$directory, $target] = $fixture();
try {
$serial = $run($target);
$parallel = $run($target, true);
expect($serial['exitCode'])->toBe(2)
->and($parallel['exitCode'])->toBe(2)
->and($serial['output'])->toContain('INFO No tests found.')
->and($parallel['output'])->toContain('INFO No tests found.')
->and($parallel['output'])->toContain('Parallel: 2 processes')
->and($parallel['output'])->not->toContain('passed');
} finally {
$cleanup($directory);
}
})->skipOnWindows();