Skip to content

Commit f75a961

Browse files
committed
fix(tests): avoid global env pollution from putenv in SidecarThreadModeRootTest
Replace putenv('DD_TRACE_TEST_SAPI=fpm-fcgi') with a new WebServer::setForceSapi() method that overrides the SAPI for a single WebServer instance only, without affecting the global process environment used by all subsequent test classes.
1 parent 632cd4a commit f75a961

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

tests/Integrations/Custom/Autoloaded/SidecarThreadModeRootTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ public static function ddSetUpBeforeClass()
4747
self::markTestSkipped('No unprivileged user found on this system (tried www-data, daemon, nobody)');
4848
}
4949

50-
// Force FPM mode regardless of the CI job's DD_TRACE_TEST_SAPI so this
51-
// test runs in every test_web_custom matrix entry, not just fpm-fcgi.
52-
putenv('DD_TRACE_TEST_SAPI=fpm-fcgi');
53-
5450
parent::ddSetUpBeforeClass();
5551
}
5652

5753
protected static function configureWebServer(WebServer $server)
5854
{
55+
// Force FPM mode for this test regardless of the CI job's DD_TRACE_TEST_SAPI,
56+
// without polluting the global env for other test classes.
57+
$server->setForceSapi('fpm-fcgi');
5958
// Tell FPM to switch worker processes to the unprivileged user after forking.
6059
$server->setPhpFpmUser(self::$workerUser);
6160
if (self::$useSudo) {

tests/WebServer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ final class WebServer
8484
private $phpFpmUser = null;
8585
private $phpFpmGroup = null;
8686
private $phpFpmSudo = false;
87+
private $forceSapi = null;
8788

8889
private $defaultInis = [
8990
'log_errors' => 'on',
@@ -152,6 +153,11 @@ public function setPhpFpmSudo($sudo = true)
152153
$this->phpFpmSudo = $sudo;
153154
}
154155

156+
public function setForceSapi($sapi)
157+
{
158+
$this->forceSapi = $sapi;
159+
}
160+
155161
public function start()
156162
{
157163
if (!isset($this->envs['DD_TRACE_DEBUG'])) {
@@ -196,7 +202,7 @@ public function start()
196202
$this->inis
197203
);
198204
} else {
199-
switch (\getenv('DD_TRACE_TEST_SAPI')) {
205+
switch ($this->forceSapi ?? \getenv('DD_TRACE_TEST_SAPI')) {
200206
case 'cgi-fcgi':
201207
$this->sapi = new PhpCgi(
202208
self::FCGI_HOST,

0 commit comments

Comments
 (0)