Skip to content

Commit 553a7b7

Browse files
Merge branch '12.5'
* 12.5: Prepare release Update ChangeLog Remove unnecessary filter Skip test if pcntl not available, remove require-dev ShutdownHandler does not output in child processes Add failing test for ShutdownHandler with child process
2 parents 295383b + a58d73f commit 553a7b7

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/Runner/ShutdownHandler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PHPUnit\Runner;
1111

1212
use const PHP_EOL;
13+
use function getmypid;
1314
use function register_shutdown_function;
1415
use 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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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)

0 commit comments

Comments
 (0)