Skip to content

Commit f0ad610

Browse files
Closes #5860
1 parent 9a3b110 commit f0ad610

5 files changed

Lines changed: 115 additions & 0 deletions

File tree

ChangeLog-12.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 12.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [12.5.21] - 2026-MM-DD
6+
7+
### Fixed
8+
9+
* [#5860](https://github.com/sebastianbergmann/phpunit/issues/5860): PHP CLI `-d` settings are not forwarded to child processes for process isolation
10+
511
## [12.5.20] - 2026-04-15
612

713
### Fixed
@@ -187,6 +193,7 @@ All notable changes of the PHPUnit 12.5 release series are documented in this fi
187193
* [#6380](https://github.com/sebastianbergmann/phpunit/pull/6380): Allow `Throwable` in `expectExceptionObject()`
188194
* A PHPUnit notice is now emitted for test methods that create a mock object but do not configure an expectation for it
189195

196+
[12.5.21]: https://github.com/sebastianbergmann/phpunit/compare/12.5.20...12.5
190197
[12.5.20]: https://github.com/sebastianbergmann/phpunit/compare/12.5.19...12.5.20
191198
[12.5.19]: https://github.com/sebastianbergmann/phpunit/compare/12.5.18...12.5.19
192199
[12.5.18]: https://github.com/sebastianbergmann/phpunit/compare/12.5.17...12.5.18

src/Util/PHP/DefaultJobRunner.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ private function buildCommand(Job $job, ?string $file): array
260260
}
261261
}
262262

263+
$phpSettings = array_merge($phpSettings, $this->cliIniOverrides($phpSettings));
264+
263265
$command = array_merge($command, $this->settingsToParameters(array_values($phpSettings)));
264266

265267
if (PHP_SAPI === 'phpdbg') {
@@ -288,6 +290,36 @@ private function buildCommand(Job $job, ?string $file): array
288290
return $command;
289291
}
290292

293+
/**
294+
* Detects INI settings that cannot be set via ini_set() (PHP_INI_SYSTEM
295+
* and PHP_INI_PERDIR) and whose current value differs from the value
296+
* configured in INI files.
297+
*
298+
* These settings must be forwarded as -d flags to child processes
299+
* because the @ini_set() calls in GlobalState::getIniSettingsAsString()
300+
* cannot change them at runtime.
301+
*
302+
* @param array<array-key, string> $alreadySet
303+
*
304+
* @return array<string, string>
305+
*/
306+
private function cliIniOverrides(array $alreadySet): array
307+
{
308+
$overrides = (new Runtime)->getSettingsNotChangeableAtRuntime();
309+
310+
foreach ($overrides as $key => $value) {
311+
foreach ($alreadySet as $existing) {
312+
if (str_starts_with($existing, $key . '=')) {
313+
unset($overrides[$key]);
314+
315+
break;
316+
}
317+
}
318+
}
319+
320+
return $overrides;
321+
}
322+
291323
/**
292324
* @param list<string> $settings
293325
*
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 defined;
13+
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
14+
use PHPUnit\Framework\TestCase;
15+
16+
final class AutoPrependFileTest extends TestCase
17+
{
18+
#[RunInSeparateProcess]
19+
public function testAutoPrependFileIsLoadedInChildProcess(): void
20+
{
21+
$this->assertTrue(defined('AUTO_PREPEND_FILE_LOADED'));
22+
}
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
\define('AUTO_PREPEND_FILE_LOADED', true);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
PHP CLI -d settings are forwarded to child processes when using process isolation
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
6+
$process = proc_open(
7+
[
8+
PHP_BINARY,
9+
'-d',
10+
'auto_prepend_file=' . __DIR__ . '/_files/auto_prepend_file.php',
11+
__DIR__ . '/../../../phpunit',
12+
'--do-not-cache-result',
13+
'--no-configuration',
14+
__DIR__ . '/_files/AutoPrependFileTest.php',
15+
],
16+
[
17+
1 => ['pipe', 'w'],
18+
2 => ['pipe', 'w'],
19+
],
20+
$pipes,
21+
);
22+
23+
print stream_get_contents($pipes[1]);
24+
fclose($pipes[1]);
25+
26+
$stderr = stream_get_contents($pipes[2]);
27+
fclose($pipes[2]);
28+
29+
proc_close($process);
30+
31+
if ($stderr !== '') {
32+
print $stderr;
33+
}
34+
--EXPECTF--
35+
PHPUnit %s by Sebastian Bergmann and contributors.
36+
37+
Runtime: %s
38+
39+
. 1 / 1 (100%)
40+
41+
Time: %s, Memory: %s
42+
43+
OK (1 test, 1 assertion)

0 commit comments

Comments
 (0)