From 87c8fd1379f8947710cd349f47f6b5e794316232 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Mon, 25 Oct 2021 17:43:34 +0200 Subject: [PATCH] [Dotenv] Fix testLoadEnv() .env.dist isolation --- Tests/DotenvTest.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Tests/DotenvTest.php b/Tests/DotenvTest.php index bfd22b1..4428658 100644 --- a/Tests/DotenvTest.php +++ b/Tests/DotenvTest.php @@ -229,15 +229,12 @@ public function testLoadEnv() $resetContext = static function (): void { unset($_ENV['SYMFONY_DOTENV_VARS']); unset($_ENV['FOO']); - unset($_ENV['BAR']); unset($_ENV['TEST_APP_ENV']); unset($_SERVER['SYMFONY_DOTENV_VARS']); unset($_SERVER['FOO']); - unset($_SERVER['BAR']); unset($_SERVER['TEST_APP_ENV']); putenv('SYMFONY_DOTENV_VARS'); putenv('FOO'); - putenv('BAR'); putenv('TEST_APP_ENV'); }; @@ -246,55 +243,54 @@ public function testLoadEnv() $path = tempnam($tmpdir, 'sf-'); // .env + file_put_contents($path, 'FOO=BAR'); $resetContext(); - file_put_contents($path, 'FOO=BAR'); (new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV'); $this->assertSame('BAR', getenv('FOO')); $this->assertSame('dev', getenv('TEST_APP_ENV')); // .env.local + file_put_contents("$path.local", 'FOO=localBAR'); $resetContext(); $_SERVER['TEST_APP_ENV'] = 'local'; - file_put_contents("$path.local", 'FOO=localBAR'); (new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV'); $this->assertSame('localBAR', getenv('FOO')); // special case for test - $resetContext(); $_SERVER['TEST_APP_ENV'] = 'test'; (new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV'); $this->assertSame('BAR', getenv('FOO')); // .env.dev + file_put_contents("$path.dev", 'FOO=devBAR'); $resetContext(); - file_put_contents("$path.dev", 'FOO=devBAR'); (new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV'); $this->assertSame('devBAR', getenv('FOO')); // .env.dev.local + file_put_contents("$path.dev.local", 'FOO=devlocalBAR'); $resetContext(); - file_put_contents("$path.dev.local", 'FOO=devlocalBAR'); (new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV'); $this->assertSame('devlocalBAR', getenv('FOO')); + unlink("$path.local"); + unlink("$path.dev"); + unlink("$path.dev.local"); // .env.dist + file_put_contents("$path.dist", 'FOO=distBAR'); $resetContext(); unlink($path); - file_put_contents("$path.dist", 'BAR=distBAR'); (new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV'); - $this->assertSame('distBAR', getenv('BAR')); + $this->assertSame('distBAR', getenv('FOO')); + unlink("$path.dist"); $resetContext(); - unlink("$path.dist"); - unlink("$path.local"); - unlink("$path.dev"); - unlink("$path.dev.local"); rmdir($tmpdir); }