diff --git a/src/Plugins/Parallel/Handlers/Laravel.php b/src/Plugins/Parallel/Handlers/Laravel.php index 7ea01696..46efee75 100644 --- a/src/Plugins/Parallel/Handlers/Laravel.php +++ b/src/Plugins/Parallel/Handlers/Laravel.php @@ -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); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 30b40bd3..5450a1ca 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -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) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 2004 passed (4509 assertions) \ No newline at end of file diff --git a/tests/Fixtures/Suites/ParallelLaravelFlags.php b/tests/Fixtures/Suites/ParallelLaravelFlags.php new file mode 100644 index 00000000..001385db --- /dev/null +++ b/tests/Fixtures/Suites/ParallelLaravelFlags.php @@ -0,0 +1,32 @@ + 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); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 9ea2d67d..813ba58f 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -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');