Skip to content

Commit

Permalink
Merge branch '5.3' into 5.4
Browse files Browse the repository at this point in the history
* 5.3:
  [Dotenv] Fix testBootEnv() to start from a fresh context
  • Loading branch information
nicolas-grekas committed Oct 26, 2021
2 parents a188c79 + 46a528c commit bb0e32e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Tests/DotenvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<?php return ["TEST_APP_ENV" => "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);
}
}

0 comments on commit bb0e32e

Please sign in to comment.