fix Laravel parallel process hooks (#2084)

Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
Razvan Aurariu
2026-11-27 14:04:00 +02:00
committed by GitHub
parent cf21b7cd64
commit 093ca57693
4 changed files with 64 additions and 4 deletions
+3 -3
View File
@@ -66,14 +66,14 @@ final class Laravel implements HandlesArguments
*/
private function ensureEnvironmentVariables(array $arguments): array
{
$_ENV['LARAVEL_PARALLEL_TESTING'] = 1;
$_SERVER['LARAVEL_PARALLEL_TESTING'] = $_ENV['LARAVEL_PARALLEL_TESTING'] = 1;
if ($this->hasArgument('--recreate-databases', $arguments)) {
$_ENV['LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES'] = 1;
$_SERVER['LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES'] = $_ENV['LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES'] = 1;
}
if ($this->hasArgument('--drop-databases', $arguments)) {
$_ENV['LARAVEL_PARALLEL_TESTING_DROP_DATABASES'] = 1;
$_SERVER['LARAVEL_PARALLEL_TESTING_DROP_DATABASES'] = $_ENV['LARAVEL_PARALLEL_TESTING_DROP_DATABASES'] = 1;
}
$arguments = $this->popArgument('--recreate-databases', $arguments);
+4 -1
View File
@@ -2589,6 +2589,9 @@
✓ a parallel test can extend another test with same name
✓ parallel reports invalid datasets as failures
✓ parallel lets extensions register event subscribers
✓ sets Laravel parallel flags with dataset "without database options"
✓ sets Laravel parallel flags with dataset "recreate databases"
✓ sets Laravel parallel flags with dataset "drop databases"
✓ parallel can have multiple exclude-groups
✓ parallel can have multiple groups
✓ parallel accepts the options that the workers ignore with ('--no-results')
@@ -2718,4 +2721,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, 39 skipped, 2001 passed (4506 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 2004 passed (4509 assertions)
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
use Composer\InstalledVersions;
use Pest\Plugins\Parallel\Handlers\Laravel;
require dirname(__DIR__, 3).'/vendor/autoload.php';
final class ParallelRunnerStub
{
public static function resolveRunnerUsing(Closure $resolver): void {}
}
class_alias(ParallelRunnerStub::class, 'Illuminate\\Testing\\ParallelRunner');
$installed = InstalledVersions::getAllRawData()[0];
$installed['versions']['laravel/framework'] = ['dev_requirement' => false];
InstalledVersions::reload($installed);
(new Laravel)->handleArguments($argv);
$flags = array_flip([
'LARAVEL_PARALLEL_TESTING',
'LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES',
'LARAVEL_PARALLEL_TESTING_DROP_DATABASES',
]);
echo json_encode([
'server' => array_keys(array_filter(array_intersect_key($_SERVER, $flags))),
'env' => array_keys(array_filter(array_intersect_key($_ENV, $flags))),
], JSON_THROW_ON_ERROR);
+25
View File
@@ -59,6 +59,31 @@ test('parallel lets extensions register event subscribers', function (): void {
->toContain('Parallel: 2 processes');
})->skipOnWindows();
test('sets Laravel parallel flags', function (array $options, array $databaseFlags): void {
$process = new Process(
[PHP_BINARY, '-d', 'auto_prepend_file=', 'tests/Fixtures/Suites/ParallelLaravelFlags.php', '--parallel', ...$options],
dirname(__DIR__, 2),
[
'LARAVEL_PARALLEL_TESTING' => false,
'LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES' => false,
'LARAVEL_PARALLEL_TESTING_DROP_DATABASES' => false,
],
);
$process->mustRun();
$expectedFlags = ['LARAVEL_PARALLEL_TESTING', ...$databaseFlags];
expect(json_decode($process->getOutput(), true, flags: JSON_THROW_ON_ERROR))->toBe([
'server' => $expectedFlags,
'env' => $expectedFlags,
]);
})->with([
'without database options' => [[], []],
'recreate databases' => [['--recreate-databases'], ['LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES']],
'drop databases' => [['--drop-databases'], ['LARAVEL_PARALLEL_TESTING_DROP_DATABASES']],
]);
test('parallel can have multiple exclude-groups', function () use ($run): void {
$singleExclude = $run('--exclude-group=integration');
$doubleExclude = $run('--exclude-group=integration', '--exclude-group=container');