Skip to content

Commit 33fb216

Browse files
Merge branch '12.5' into 13.1
* 12.5: Closes #6465
2 parents 5de0c5a + 77490c4 commit 33fb216

4 files changed

Lines changed: 76 additions & 0 deletions

File tree

ChangeLog-13.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes of the PHPUnit 13.1 release series are documented in this fi
77
### Fixed
88

99
* [#5993](https://github.com/sebastianbergmann/phpunit/issues/5993): `DefaultJobRunner` deadlocks on child processes that write large amounts of stderr output
10+
* [#6465](https://github.com/sebastianbergmann/phpunit/issues/6465): SAPI-populated `$_SERVER` entries leak from parent into child process
1011
* [#6587](https://github.com/sebastianbergmann/phpunit/issues/6587): `failOnEmptyTestSuite="false"` in `phpunit.xml` is ignored when `--group`/`--filter`/`--testsuite` matches no tests
1112

1213
## [13.1.3] - 2026-04-13

src/Util/GlobalState.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@
5252
'_REQUEST',
5353
];
5454

55+
/**
56+
* Keys in $_SERVER that are populated by the SAPI in the child process
57+
* and must therefore not be preserved from the parent process.
58+
*
59+
* @var non-empty-list<non-empty-string>
60+
*/
61+
private const array SAPI_SERVER_KEYS = [
62+
'PHP_SELF',
63+
'SCRIPT_NAME',
64+
'SCRIPT_FILENAME',
65+
'PATH_TRANSLATED',
66+
'DOCUMENT_ROOT',
67+
'REQUEST_TIME',
68+
'REQUEST_TIME_FLOAT',
69+
'argv',
70+
'argc',
71+
];
72+
5573
/**
5674
* @var non-empty-array<non-empty-string, non-empty-array<non-empty-string, true>>
5775
*/
@@ -271,6 +289,10 @@ public static function exportGlobals(): GlobalStateResult
271289
foreach (self::SUPER_GLOBAL_ARRAYS as $superGlobalArray) {
272290
if (isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray])) {
273291
foreach ($GLOBALS[$superGlobalArray] as $key => $value) {
292+
if ($superGlobalArray === '_SERVER' && in_array($key, self::SAPI_SERVER_KEYS, true)) {
293+
continue;
294+
}
295+
274296
$name = sprintf('$GLOBALS[\'%s\'][\'%s\']', $superGlobalArray, $key);
275297

276298
if ($value instanceof Closure) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6465
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['REQUEST_TIME_FLOAT'] = 1.0;
6+
$_SERVER['REQUEST_TIME'] = 1;
7+
$_SERVER['SCRIPT_FILENAME'] = '/fake/parent/script.php';
8+
9+
$_SERVER['argv'][] = '--do-not-cache-result';
10+
$_SERVER['argv'][] = '--no-configuration';
11+
$_SERVER['argv'][] = __DIR__ . '/6465/Issue6465Test.php';
12+
13+
require_once __DIR__ . '/../../bootstrap.php';
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
PHPUnit %s by Sebastian Bergmann and contributors.
17+
18+
Runtime: %s
19+
20+
.. 2 / 2 (100%)
21+
22+
Time: %s, Memory: %s
23+
24+
OK (2 tests, 3 assertions)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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\Issue6465;
11+
12+
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class Issue6465Test extends TestCase
16+
{
17+
#[RunInSeparateProcess]
18+
public function testRequestTimeFloatIsNotInheritedFromParent(): void
19+
{
20+
$this->assertNotSame(1.0, $_SERVER['REQUEST_TIME_FLOAT']);
21+
$this->assertNotSame(1, $_SERVER['REQUEST_TIME']);
22+
}
23+
24+
#[RunInSeparateProcess]
25+
public function testScriptFilenameIsNotInheritedFromParent(): void
26+
{
27+
$this->assertNotSame('/fake/parent/script.php', $_SERVER['SCRIPT_FILENAME']);
28+
}
29+
}

0 commit comments

Comments
 (0)