From 46a528ca327e0cb7fa7493a98ed3aebef8a516ac Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Tue, 26 Oct 2021 17:34:45 +0200 Subject: [PATCH] [Dotenv] Fix testBootEnv() to start from a fresh context --- Tests/DotenvTest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Tests/DotenvTest.php b/Tests/DotenvTest.php index 36dcc59..c337142 100644 --- a/Tests/DotenvTest.php +++ b/Tests/DotenvTest.php @@ -485,24 +485,30 @@ public function testDoNotUsePutenv() public function testBootEnv() { + $resetContext = static function (): void { + unset($_SERVER['SYMFONY_DOTENV_VARS'], $_ENV['SYMFONY_DOTENV_VARS']); + unset($_SERVER['TEST_APP_ENV'], $_ENV['TEST_APP_ENV']); + unset($_SERVER['TEST_APP_DEBUG'], $_ENV['TEST_APP_DEBUG']); + unset($_SERVER['FOO'], $_ENV['FOO']); + }; + @mkdir($tmpdir = sys_get_temp_dir().'/dotenv'); $path = tempnam($tmpdir, 'sf-'); file_put_contents($path, 'FOO=BAR'); + $resetContext(); (new Dotenv('TEST_APP_ENV', 'TEST_APP_DEBUG'))->bootEnv($path); - $this->assertSame('BAR', $_SERVER['FOO']); - - unset($_SERVER['FOO'], $_ENV['FOO']); unlink($path); file_put_contents($path.'.local.php', ' "dev", "FOO" => "BAR"];'); + $resetContext(); (new Dotenv('TEST_APP_ENV', 'TEST_APP_DEBUG'))->bootEnv($path); $this->assertSame('BAR', $_SERVER['FOO']); $this->assertSame('1', $_SERVER['TEST_APP_DEBUG']); - - unset($_SERVER['FOO'], $_ENV['FOO']); unlink($path.'.local.php'); + + $resetContext(); rmdir($tmpdir); } }