File tree Expand file tree Collapse file tree 3 files changed +60
-2
lines changed Expand file tree Collapse file tree 3 files changed +60
-2
lines changed Original file line number Diff line number Diff line change 1010namespace PHPUnit \Runner ;
1111
1212use const PHP_EOL ;
13+ use function getmypid ;
1314use function register_shutdown_function ;
1415use function rtrim ;
1516
@@ -42,13 +43,14 @@ private static function register(): void
4243 }
4344
4445 self ::$ registered = true ;
46+ $ pid = getmypid ();
4547
4648 register_shutdown_function (
47- static function (): void
49+ static function () use ( $ pid ) : void
4850 {
4951 $ message = rtrim (self ::$ message );
5052
51- if ($ message === '' ) {
53+ if ($ message === '' || $ pid !== getmypid () ) {
5254 return ;
5355 }
5456
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+ /*
3+ * This file is part of PHPUnit.
4+ *
5+ * (c) Sebastian Bergmann <[email protected] > 6+ *
7+ * For the full copyright and license information, please view the LICENSE
8+ * file that was distributed with this source code.
9+ */
10+ namespace PHPUnit \TestFixture ;
11+
12+ use function pcntl_fork ;
13+ use function pcntl_wait ;
14+ use PHPUnit \Framework \TestCase ;
15+
16+ final class ChildProcessTest extends TestCase
17+ {
18+ public function testChildProcessOutput (): void
19+ {
20+ $ child = pcntl_fork ();
21+ $ this ->assertGreaterThan (-1 , $ child );
22+
23+ if ($ child ) {
24+ pcntl_wait ($ child );
25+ $ this ->assertTrue (true );
26+ } else {
27+ exit (0 );
28+ }
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ --TEST--
2+ ShutdownHandler does not output when child process exits
3+ --SKIPIF--
4+ <?php declare (strict_types=1 );
5+ if (!extension_loaded ('pcntl ' )) {
6+ print 'skip: Extension pcntl must be loaded. ' ;
7+ }
8+ --FILE --
9+ <?php declare (strict_types=1 );
10+ $ _SERVER ['argv ' ][] = '--do-not-cache-result ' ;
11+ $ _SERVER ['argv ' ][] = '--no-configuration ' ;
12+ $ _SERVER ['argv ' ][] = __DIR__ . '/../_files/ChildProcessTest.php ' ;
13+
14+ require __DIR__ . '/../../bootstrap.php ' ;
15+
16+ (new PHPUnit \TextUI \Application )->run ($ _SERVER ['argv ' ]);
17+ --EXPECTF --
18+ PHPUnit %s by Sebastian Bergmann and contributors.
19+
20+ Runtime: %s
21+
22+ . 1 / 1 (100 %)
23+
24+ Time: %s, Memory: %s
25+
26+ OK (1 test, 2 assertions)
You can’t perform that action at this time.
0 commit comments