@@ -314,4 +314,110 @@ public function testGetEnvUnknown()
314314 return 'foo ' ;
315315 });
316316 }
317+
318+ /**
319+ * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
320+ * @expectedExceptionMessage Invalid configuration: env var "key:foo" does not contain a key specifier.
321+ */
322+ public function testGetEnvKeyInvalidKey ()
323+ {
324+ $ processor = new EnvVarProcessor (new Container ());
325+
326+ $ processor ->getEnv ('key ' , 'foo ' , function ($ name ) {
327+ $ this ->fail ('Should not get here ' );
328+ });
329+ }
330+
331+ /**
332+ * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
333+ * @expectedExceptionMessage Resolved value of "foo" did not result in an array value.
334+ * @dataProvider noArrayValues
335+ */
336+ public function testGetEnvKeyNoArrayResult ($ value )
337+ {
338+ $ processor = new EnvVarProcessor (new Container ());
339+
340+ $ processor ->getEnv ('key ' , 'index:foo ' , function ($ name ) use ($ value ) {
341+ $ this ->assertSame ('foo ' , $ name );
342+
343+ return $ value ;
344+ });
345+ }
346+
347+ public function noArrayValues ()
348+ {
349+ return array (
350+ array (null ),
351+ array ('string ' ),
352+ array (1 ),
353+ array (true ),
354+ );
355+ }
356+
357+ /**
358+ * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
359+ * @expectedExceptionMessage Key "index" not found in
360+ * @dataProvider invalidArrayValues
361+ */
362+ public function testGetEnvKeyArrayKeyNotFound ($ value )
363+ {
364+ $ processor = new EnvVarProcessor (new Container ());
365+
366+ $ processor ->getEnv ('key ' , 'index:foo ' , function ($ name ) use ($ value ) {
367+ $ this ->assertSame ('foo ' , $ name );
368+
369+ return $ value ;
370+ });
371+ }
372+
373+ public function invalidArrayValues ()
374+ {
375+ return array (
376+ array (array ()),
377+ array (array ('index2 ' => 'value ' )),
378+ array (array ('index ' , 'index2 ' )),
379+ );
380+ }
381+
382+ /**
383+ * @dataProvider arrayValues
384+ */
385+ public function testGetEnvKey ($ value )
386+ {
387+ $ processor = new EnvVarProcessor (new Container ());
388+
389+ $ this ->assertSame ($ value ['index ' ], $ processor ->getEnv ('key ' , 'index:foo ' , function ($ name ) use ($ value ) {
390+ $ this ->assertSame ('foo ' , $ name );
391+
392+ return $ value ;
393+ }));
394+ }
395+
396+ public function arrayValues ()
397+ {
398+ return array (
399+ array (array ('index ' => 'password ' )),
400+ array (array ('index ' => 'true ' )),
401+ array (array ('index ' => false )),
402+ array (array ('index ' => '1 ' )),
403+ array (array ('index ' => 1 )),
404+ array (array ('index ' => '1.1 ' )),
405+ array (array ('index ' => 1.1 )),
406+ array (array ('index ' => array ())),
407+ array (array ('index ' => array ('val1 ' , 'val2 ' ))),
408+ );
409+ }
410+
411+ public function testGetEnvKeyChained ()
412+ {
413+ $ processor = new EnvVarProcessor (new Container ());
414+
415+ $ this ->assertSame ('password ' , $ processor ->getEnv ('key ' , 'index:file:foo ' , function ($ name ) {
416+ $ this ->assertSame ('file:foo ' , $ name );
417+
418+ return array (
419+ 'index ' => 'password ' ,
420+ );
421+ }));
422+ }
317423}
0 commit comments