8000 minor #43697 [Dotenv] Fix testLoadEnv() .env.dist isolation (fancyweb) · symfony/symfony@7d20c4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d20c4d

Browse files
minor #43697 [Dotenv] Fix testLoadEnv() .env.dist isolation (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [Dotenv] Fix testLoadEnv() .env.dist isolation | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Sorry but I did not catch everything in the first one. When `.env.dist` is tested, `.env.local` , `.env.dev` and `.env.dev.local` still exists and "override" defined vars in `.env.dist`. I guess that's why you used another var (`BAR`). It makes more sense to me to actually test it "in isolation" since we don't test anything about the override right now. Also, I applied some minor changes to minimize the diff on changes I'm working on for adding `$overrideExistingVars` to `loadEnv()` and `bootEnv()`. Commits ------- ae63960 [Dotenv] Fix testLoadEnv() .env.dist isolation
2 parents abb43f7 + ae63960 commit 7d20c4d

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,12 @@ public function testLoadEnv()
229229
$resetContext = static function (): void {
230230
unset($_ENV['SYMFONY_DOTENV_VARS']);
231231
unset($_ENV['FOO']);
232-
unset($_ENV['BAR']);
233232
unset($_ENV['TEST_APP_ENV']);
234233
unset($_SERVER['SYMFONY_DOTENV_VARS']);
235234
unset($_SERVER['FOO']);
236-
unset($_SERVER['BAR']);
237235
unset($_SERVER['TEST_APP_ENV']);
238236
putenv('SYMFONY_DOTENV_VARS');
239237
putenv('FOO');
240-
putenv('BAR');
241238
putenv('TEST_APP_ENV');
242239
};
243240

@@ -246,55 +243,54 @@ public function testLoadEnv()
246243
$path = tempnam($tmpdir, 'sf-');
247244

248245
// .env
246+
file_put_contents($path, 'FOO=BAR');
249247

250248
$resetContext();
251-
file_put_contents($path, 'FOO=BAR');
252249
(new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV');
253250
$this->assertSame('BAR', getenv('FOO'));
254251
$this->assertSame('dev', getenv('TEST_APP_ENV'));
255252

256253
// .env.local
254+
file_put_contents("$path.local", 'FOO=localBAR');
257255

258256
$resetContext();
259257
$_SERVER['TEST_APP_ENV'] = 'local';
260-
file_put_contents("$path.local", 'FOO=localBAR');
261258
(new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV');
262259
$this->assertSame('localBAR', getenv('FOO'));
263260

264261
// special case for test
265-
266262
$resetContext();
267263
$_SERVER['TEST_APP_ENV'] = 'test';
268264
(new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV');
269265
$this->assertSame('BAR', getenv('FOO'));
270266

271267
// .env.dev
268+
file_put_contents("$path.dev", 'FOO=devBAR');
272269

273270
$resetContext();
274-
file_put_contents("$path.dev", 'FOO=devBAR');
275271
(new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV');
276272
$this->assertSame('devBAR', getenv('FOO'));
277273

278274
// .env.dev.local
275+
file_put_contents("$path.dev.local", 'FOO=devlocalBAR');
279276

280277
$resetContext();
281-
file_put_contents("$path.dev.local", 'FOO=devlocalBAR');
282278
(new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV');
283279
$this->assertSame('devlocalBAR', getenv('FOO'));
280+
unlink("$path.local");
281+
unlink("$path.dev");
282+
unlink("$path.dev.local");
284283

285284
// .env.dist
285+
file_put_contents("$path.dist", 'FOO=distBAR');
286286

287287
$resetContext();
288288
unlink($path);
289-
file_put_contents("$path.dist", 'BAR=distBAR');
290289
(new Dotenv(true))->loadEnv($path, 'TEST_APP_ENV');
291-
$this->assertSame('distBAR', getenv('BAR'));
290+
$this->assertSame('distBAR', getenv('FOO'));
291+
unlink("$path.dist");
292292

293293
$resetContext();
294-
unlink("$path.dist");
295-
unlink("$path.local");
296-
unlink("$path.dev");
297-
unlink("$path.dev.local");
298294
rmdir($tmpdir);
299295
}
300296

0 commit comments

Comments
 (0)
0