From b00dfb538be78b621ee014d6e8b1807c07e6a706 Mon Sep 17 00:00:00 2001 From: Jawira Portugal Date: Mon, 16 Dec 2024 19:04:04 +0100 Subject: [PATCH] Use getenv() function instead of $_ENV global variable. (#1887) * ComposerTask: update code & doc #1163 * refactor(PropertyTask): Use getenv() function instead of $_ENV global variable. The PropertyTask's "environment" attribute fails to work as expected in some systems, sometimes $_ENV is an empty array. This behavior is system-dependent and determined by the "variables_order" directive in php.ini. To fix this I replaced $_ENV by getenv() function, as this ensures a consistent behaviour. * https://www.php.net/manual/en/ini.core.php#ini.variables-order * https://stackoverflow.com/questions/8798294/getenv-vs-env-in-php --- src/Phing/Task/System/PropertyTask.php | 2 +- tests/Phing/Test/Task/System/PropertyTaskTest.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Phing/Task/System/PropertyTask.php b/src/Phing/Task/System/PropertyTask.php index 97574c1af..51dfb7870 100644 --- a/src/Phing/Task/System/PropertyTask.php +++ b/src/Phing/Task/System/PropertyTask.php @@ -412,7 +412,7 @@ protected function loadEnvironment(string $prefix) $prefix .= '.'; } $this->log("Loading Environment {$prefix}", Project::MSG_VERBOSE); - foreach ($_ENV as $key => $value) { + foreach (getenv() as $key => $value) { $props->setProperty($prefix . '.' . $key, $value); } $this->addProperties($props); diff --git a/tests/Phing/Test/Task/System/PropertyTaskTest.php b/tests/Phing/Test/Task/System/PropertyTaskTest.php index 3b924e54b..e7c1affef 100644 --- a/tests/Phing/Test/Task/System/PropertyTaskTest.php +++ b/tests/Phing/Test/Task/System/PropertyTaskTest.php @@ -38,8 +38,9 @@ public function setUp(): void public function test1(): void { - // should get no output at all - $this->expectOutputAndError('test1', '', ''); + putenv('MESSAGE=foo bar baz'); + $this->executeTarget(__FUNCTION__); + $this->assertPropertyEquals('testenv.MESSAGE', 'foo bar baz'); } public function test2(): void