From 3bf7e490b0ac399b963a340f868c49f00001ec44 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Fri, 21 Apr 2017 19:58:37 +0200 Subject: [PATCH 1/3] [DotEnv] Don't override existing $_SERVER vars --- src/Symfony/Component/Dotenv/Dotenv.php | 2 +- .../Component/Dotenv/Tests/DotenvTest.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Dotenv/Dotenv.php b/src/Symfony/Component/Dotenv/Dotenv.php index 49cdf78d682c..a7435f2ef926 100644 --- a/src/Symfony/Component/Dotenv/Dotenv.php +++ b/src/Symfony/Component/Dotenv/Dotenv.php @@ -67,7 +67,7 @@ public function load($path/*, ...$paths*/) public function populate($values) { foreach ($values as $name => $value) { - if (isset($_ENV[$name]) || false !== getenv($name)) { + if (isset($_ENV[$name]) || isset($_SERVER[$name]) || false !== getenv($name)) { continue; } diff --git a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php index 525848b42ea8..0c3cc418df47 100644 --- a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php +++ b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php @@ -154,4 +154,24 @@ public function testLoadDirectory() $dotenv = new Dotenv(); $dotenv->load(__DIR__); } + + public function testServerSuperglobalIsNotOverriden() + { + $baseValue = $_SERVER['argc']; + + $dotenv = new DotEnv(); + $dotenv->populate(array('argc' => 'whatever')); + + $this->assertSame($baseValue, $_SERVER['argc']); + } + + public function testEnvVarIsNotOverriden() + { + putenv('TEST_ENV_VAR=test_var'); + + $dotenv = new DotEnv(); + $dotenv->populate(array('TEST_ENV_VAR' => 'whatever')); + + $this->assertSame('test_var', getenv('TEST_ENV_VAR')); + } } From 0a95d89ed7f7df451a274b6a9676e40db244ccb0 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 24 Apr 2017 12:00:12 +0200 Subject: [PATCH 2/3] Minor changes to make tests more readable --- src/Symfony/Component/Dotenv/Tests/DotenvTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php index 0c3cc418df47..2bdbd6d47db0 100644 --- a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php +++ b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php @@ -157,21 +157,21 @@ public function testLoadDirectory() public function testServerSuperglobalIsNotOverriden() { - $baseValue = $_SERVER['argc']; + $originalValue = $_SERVER['argc']; $dotenv = new DotEnv(); - $dotenv->populate(array('argc' => 'whatever')); + $dotenv->populate(array('argc' => 'newValue')); - $this->assertSame($baseValue, $_SERVER['argc']); + $this->assertSame($originalValue, $_SERVER['argc']); } public function testEnvVarIsNotOverriden() { - putenv('TEST_ENV_VAR=test_var'); + putenv('TEST_ENV_VAR=original_value'); $dotenv = new DotEnv(); - $dotenv->populate(array('TEST_ENV_VAR' => 'whatever')); + $dotenv->populate(array('TEST_ENV_VAR' => 'new_value')); - $this->assertSame('test_var', getenv('TEST_ENV_VAR')); + $this->assertSame('original_value', getenv('TEST_ENV_VAR')); } } From e5758317b1497221aedc607e6158d73612db610a Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Mon, 24 Apr 2017 12:32:00 +0200 Subject: [PATCH 3/3] Update a test value for consistency --- src/Symfony/Component/Dotenv/Tests/DotenvTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php index 2bdbd6d47db0..85204e5c476a 100644 --- a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php +++ b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php @@ -160,7 +160,7 @@ public function testServerSuperglobalIsNotOverriden() $originalValue = $_SERVER['argc']; $dotenv = new DotEnv(); - $dotenv->populate(array('argc' => 'newValue')); + $dotenv->populate(array('argc' => 'new_value')); $this->assertSame($originalValue, $_SERVER['argc']); }