Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0dc7fa1

Browse filesBrowse files
Merge branch '5.3' into 5.4
* 5.3: [Dotenv] Fix testLoadEnv() .env.dist isolation
2 parents 5107582 + 9ea01eb commit 0dc7fa1
Copy full SHA for 0dc7fa1

File tree

1 file changed

+10
-14
lines changed
Filter options

1 file changed

+10
-14
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dotenv/Tests/DotenvTest.php
+10-14Lines 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())->usePutenv()->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())->usePutenv()->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())->usePutenv()->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())->usePutenv()->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())->usePutenv()->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())->usePutenv()->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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.