diff --git a/Dotenv.php b/Dotenv.php index f249ca8..2c76d52 100644 --- a/Dotenv.php +++ b/Dotenv.php @@ -151,7 +151,7 @@ public function bootEnv(string $path, string $defaultEnv = 'dev', array $testEnv $env = is_file($p) ? include $p : null; $k = $this->envKey; - if (\is_array($env) && (!isset($env[$k]) || ($_SERVER[$k] ?? $_ENV[$k] ?? $env[$k]) === $env[$k])) { + if (\is_array($env) && ($overrideExistingVars || !isset($env[$k]) || ($_SERVER[$k] ?? $_ENV[$k] ?? $env[$k]) === $env[$k])) { $this->populate($env, $overrideExistingVars); } else { $this->loadEnv($path, $k, $defaultEnv, $testEnvs, $overrideExistingVars); diff --git a/Tests/DotenvTest.php b/Tests/DotenvTest.php index 4345792..47c9bfb 100644 --- a/Tests/DotenvTest.php +++ b/Tests/DotenvTest.php @@ -587,6 +587,13 @@ public function testBootEnv() $this->assertSame('BAR', $_SERVER['FOO']); $this->assertSame('1', $_SERVER['TEST_APP_DEBUG']); $this->assertSame('localphpNEW_VALUE', $_SERVER['EXISTING_KEY']); + + $resetContext(); + $_SERVER['TEST_APP_ENV'] = 'ccc'; + (new Dotenv('TEST_APP_ENV', 'TEST_APP_DEBUG'))->bootEnv($path, 'dev', ['test'], true); + $this->assertSame('BAR', $_SERVER['FOO']); + $this->assertSame('1', $_SERVER['TEST_APP_DEBUG']); + $this->assertSame('localphpNEW_VALUE', $_SERVER['EXISTING_KEY']); unlink($path.'.local.php'); $resetContext();