mirror of
https://github.com/pestphp/pest.git
synced 2026-04-21 06:27:28 +02:00
Fix parallel dataset reporting and nested fixtures
This commit is contained in:
@ -2,58 +2,13 @@
|
||||
|
||||
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'];
|
||||
$run = function (bool $parallel = false): array {
|
||||
$command = [
|
||||
'php',
|
||||
'bin/pest',
|
||||
'tests/Fixtures/ParallelNestedDatasets/TestFileWithNestedDataset.php',
|
||||
'--colors=never',
|
||||
];
|
||||
|
||||
if ($parallel) {
|
||||
$command[] = '--parallel';
|
||||
@ -72,20 +27,14 @@ $run = function (string $target, bool $parallel = false): array {
|
||||
];
|
||||
};
|
||||
|
||||
test('parallel reports missing nested datasets without a passing summary', function () use ($cleanup, $fixture, $run) {
|
||||
[$directory, $target] = $fixture();
|
||||
test('parallel loads nested datasets from nested directories', function () use ($run) {
|
||||
$serial = $run();
|
||||
$parallel = $run(true);
|
||||
|
||||
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);
|
||||
}
|
||||
expect($serial['exitCode'])->toBe(0)
|
||||
->and($parallel['exitCode'])->toBe(0)
|
||||
->and($serial['output'])->toContain('Tests: 2 passed (2 assertions)')
|
||||
->and($parallel['output'])->toContain('Tests: 2 passed (2 assertions)')
|
||||
->and($parallel['output'])->toContain('Parallel: 2 processes')
|
||||
->and($parallel['output'])->not->toContain('No tests found.');
|
||||
})->skipOnWindows();
|
||||
|
||||
Reference in New Issue
Block a user