Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Runner/ShutdownHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace PHPUnit\Runner;

use const PHP_EOL;
use function getmypid;
use function register_shutdown_function;
use function rtrim;

Expand Down Expand Up @@ -42,13 +43,14 @@ private static function register(): void
}

self::$registered = true;
$pid = getmypid();

register_shutdown_function(
static function (): void
static function () use ($pid): void
{
$message = rtrim(self::$message);

if ($message === '') {
if ($message === '' || $pid !== getmypid()) {
return;
}

Expand Down
30 changes: 30 additions & 0 deletions tests/end-to-end/_files/ChildProcessTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture;

use function pcntl_fork;
use function pcntl_wait;
use PHPUnit\Framework\TestCase;

final class ChildProcessTest extends TestCase
{
public function testChildProcessOutput(): void
{
$child = pcntl_fork();
$this->assertGreaterThan(-1, $child);

if ($child) {
pcntl_wait($child);
$this->assertTrue(true);
} else {
exit(0);
}
}
}
26 changes: 26 additions & 0 deletions tests/end-to-end/cli/child-process-output.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
ShutdownHandler does not output when child process exits
--SKIPIF--
<?php declare(strict_types=1);
if (!extension_loaded('pcntl')) {
print 'skip: Extension pcntl must be loaded.';
}
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/ChildProcessTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s

OK (1 test, 2 assertions)