@@ -214,4 +214,60 @@ public function testEnvVarIsNotOverriden()
214
214
215
215
$ this ->assertSame ('original_value ' , getenv ('TEST_ENV_VAR ' ));
216
216
}
217
+
218
+ public function testMemorizingLoadedVarsNamesInSpecialVar ()
219
+ {
220
+ // Special variable not exists
221
+ unset($ _ENV ['SYMFONY_DOTENV_VARS ' ]);
222
+ unset($ _SERVER ['SYMFONY_DOTENV_VARS ' ]);
223
+ putenv ('SYMFONY_DOTENV_VARS ' );
224
+
225
+ unset($ _ENV ['APP_DEBUG ' ]);
226
+ unset($ _SERVER ['APP_DEBUG ' ]);
227
+ putenv ('APP_DEBUG ' );
228
+ unset($ _ENV ['DATABASE_URL ' ]);
229
+ unset($ _SERVER ['DATABASE_URL ' ]);
230
+ putenv ('DATABASE_URL ' );
231
+
232
+ $ dotenv = new DotEnv ();
233
+ $ dotenv ->populate (array ('APP_DEBUG ' => '1 ' , 'DATABASE_URL ' => 'mysql://root@localhost/db ' ));
234
+
235
+ $ this ->assertSame ('APP_DEBUG,DATABASE_URL ' , getenv ('SYMFONY_DOTENV_VARS ' ));
236
+
237
+ // Special variable has a value
238
+ $ _ENV ['SYMFONY_DOTENV_VARS ' ] = 'APP_ENV ' ;
239
+ $ _SERVER ['SYMFONY_DOTENV_VARS ' ] = 'APP_ENV ' ;
240
+ putenv ('SYMFONY_DOTENV_VARS=APP_ENV ' );
241
+
242
+ $ _ENV ['APP_DEBUG ' ] = '1 ' ;
243
+ $ _SERVER ['APP_DEBUG ' ] = '1 ' ;
244
+ putenv ('APP_DEBUG=1 ' );
245
+ unset($ _ENV ['DATABASE_URL ' ]);
246
+ unset($ _SERVER ['DATABASE_URL ' ]);
247
+ putenv ('DATABASE_URL ' );
248
+
249
+ $ dotenv = new DotEnv ();
250
+ $ dotenv ->populate (array ('APP_DEBUG ' => '0 ' , 'DATABASE_URL ' => 'mysql://root@localhost/db ' ));
251
+ $ dotenv ->populate (array ('DATABASE_URL ' => 'sqlite:///somedb.sqlite ' ));
252
+
253
+ $ this ->assertSame ('APP_ENV,DATABASE_URL ' , getenv ('SYMFONY_DOTENV_VARS ' ));
254
+ }
255
+
256
+ public function testOverridingEnvVarsWithNamesMemorizedInSpecialVar ()
257
+ {
258
+ putenv ('SYMFONY_DOTENV_VARS=FOO,BAR,BAZ ' );
259
+
260
+ putenv ('FOO=foo ' );
261
+ putenv ('BAR=bar ' );
262
+ putenv ('BAZ=baz ' );
263
+ putenv ('DOCUMENT_ROOT=/var/www ' );
264
+
265
+ $ dotenv = new DotEnv ();
266
+ $ dotenv ->populate (array ('FOO ' => 'foo1 ' , 'BAR ' => 'bar1 ' , 'BAZ ' => 'baz1 ' , 'DOCUMENT_ROOT ' => '/boot ' ));
267
+
268
+ $ this ->assertSame ('foo1 ' , getenv ('FOO ' ));
269
+ $ this ->assertSame ('bar1 ' , getenv ('BAR ' ));
270
+ $ this ->assertSame ('baz1 ' , getenv ('BAZ ' ));
271
+ $ this ->assertSame ('/var/www ' , getenv ('DOCUMENT_ROOT ' ));
272
+ }
217
273
}
0 commit comments