Skip to content

Commit 8a84b2a

Browse files
mattsebastianbergmann
authored andcommitted
Add failing test for ShutdownHandler with child process
1 parent 08125f0 commit 8a84b2a

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
"sebastian/version": "^6.0.0",
4949
"staabm/side-effects-detector": "^1.0.5"
5050
},
51+
"require-dev": {
52+
"ext-pcntl": "*"
53+
},
5154
"config": {
5255
"platform": {
5356
"php": "8.3.0"
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 <sebastian@phpunit.de>
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
ShutdownHandler does not output when child process exits
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--filter';
8+
$_SERVER['argv'][] = 'testChildProcessOutput';
9+
$_SERVER['argv'][] = __DIR__ . '/../_files/ChildProcessTest.php';
10+
11+
require __DIR__ . '/../../bootstrap.php';
12+
13+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
Runtime: %s
18+
19+
. 1 / 1 (100%)
20+
21+
Time: %s, Memory: %s
22+
23+
OK (1 test, 2 assertions)

0 commit comments

Comments
 (0)