|
| 1 | +--TEST-- |
| 2 | +Redirected tests work in parallel runs and update the progress total |
| 3 | +--ENV-- |
| 4 | +TEST_PHP_FORK_SERVER=0 |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +function writeRedirectedTest(string $file, string $name): void |
| 8 | +{ |
| 9 | + file_put_contents($file, <<<PHPT |
| 10 | + --TEST-- |
| 11 | + $name |
| 12 | + --FILE-- |
| 13 | + <?php echo "ok\\n"; ?> |
| 14 | + --EXPECT-- |
| 15 | + ok |
| 16 | + PHPT); |
| 17 | +} |
| 18 | + |
| 19 | +function runRedirectedTests(array $testFiles): array |
| 20 | +{ |
| 21 | + $command = [ |
| 22 | + getenv('TEST_PHP_EXECUTABLE'), |
| 23 | + '-n', |
| 24 | + dirname(__DIR__, 2) . '/run-tests.php', |
| 25 | + '-n', |
| 26 | + '-q', |
| 27 | + '-j2', |
| 28 | + '--progress', |
| 29 | + ...$testFiles, |
| 30 | + ]; |
| 31 | + $environment = [ |
| 32 | + 'PATH' => getenv('PATH'), |
| 33 | + 'TEST_PHP_EXECUTABLE' => getenv('TEST_PHP_EXECUTABLE'), |
| 34 | + 'TEST_PHP_FORK_SERVER' => '0', |
| 35 | + ]; |
| 36 | + foreach (['SystemRoot', 'TEMP', 'TMPDIR'] as $name) { |
| 37 | + if (($value = getenv($name)) !== false) { |
| 38 | + $environment[$name] = $value; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + $process = proc_open( |
| 43 | + $command, |
| 44 | + [ |
| 45 | + 0 => ['pipe', 'r'], |
| 46 | + 1 => ['pipe', 'w'], |
| 47 | + 2 => ['redirect', 1], |
| 48 | + ], |
| 49 | + $pipes, |
| 50 | + null, |
| 51 | + $environment, |
| 52 | + ); |
| 53 | + fclose($pipes[0]); |
| 54 | + $output = stream_get_contents($pipes[1]); |
| 55 | + fclose($pipes[1]); |
| 56 | + return [proc_close($process), str_replace("\r", "\n", $output)]; |
| 57 | +} |
| 58 | + |
| 59 | +$root = __DIR__ . '/redirected_parallel_' . getmypid(); |
| 60 | +$targets = $root . '/targets'; |
| 61 | +mkdir($targets, recursive: true); |
| 62 | + |
| 63 | +writeRedirectedTest($targets . '/one.phpt', 'redirected one'); |
| 64 | +writeRedirectedTest($targets . '/two.phpt', 'redirected two'); |
| 65 | + |
| 66 | +$targetExpression = var_export($targets, true); |
| 67 | +$redirect = $root . '/redirect.phpt'; |
| 68 | +file_put_contents($redirect, <<<PHPT |
| 69 | + --TEST-- |
| 70 | + redirect wrapper |
| 71 | + --REDIRECTTEST-- |
| 72 | + return ['ENV' => [], 'TESTS' => $targetExpression]; |
| 73 | + PHPT); |
| 74 | +writeRedirectedTest($root . '/companion.phpt', 'companion'); |
| 75 | + |
| 76 | +[$singleExitCode, $singleOutput] = runRedirectedTests([$redirect]); |
| 77 | +if ($singleExitCode !== 0) { |
| 78 | + echo $singleOutput; |
| 79 | +} |
| 80 | +var_dump($singleExitCode); |
| 81 | +var_dump(str_contains($singleOutput, 'Fatal error')); |
| 82 | + |
| 83 | +[$parallelExitCode, $parallelOutput] = runRedirectedTests([ |
| 84 | + $redirect, |
| 85 | + $root . '/companion.phpt', |
| 86 | +]); |
| 87 | +if ($parallelExitCode !== 0) { |
| 88 | + echo $parallelOutput; |
| 89 | +} |
| 90 | +var_dump($parallelExitCode); |
| 91 | +var_dump(str_contains($parallelOutput, 'TEST 3/3')); |
| 92 | +var_dump(str_contains($parallelOutput, 'TEST 3/2')); |
| 93 | +?> |
| 94 | +--CLEAN-- |
| 95 | +<?php |
| 96 | +foreach (glob(__DIR__ . '/redirected_parallel_*') ?: [] as $root) { |
| 97 | + foreach (glob($root . '/targets/*') ?: [] as $file) { |
| 98 | + unlink($file); |
| 99 | + } |
| 100 | + @rmdir($root . '/targets'); |
| 101 | + @unlink($root . '/redirect.phpt'); |
| 102 | + @unlink($root . '/companion.phpt'); |
| 103 | + @rmdir($root); |
| 104 | +} |
| 105 | +?> |
| 106 | +--EXPECT-- |
| 107 | +int(0) |
| 108 | +bool(false) |
| 109 | +int(0) |
| 110 | +bool(true) |
| 111 | +bool(false) |
0 commit comments