@@ -314,4 +314,94 @@ public function testGetEnvUnknown()
314
314
return 'foo ' ;
315
315
});
316
316
}
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
+ public function testGetEnvKey ()
383
+ {
384
+ $ processor = new EnvVarProcessor (new Container ());
385
+
386
+ $ this ->assertSame ('password ' , $ processor ->getEnv ('key ' , 'index:foo ' , function ($ name ) {
387
+ $ this ->assertSame ('foo ' , $ name );
388
+
389
+ return array (
390
+ 'index ' => 'password ' ,
391
+ );
392
+ }));
393
+ }
394
+
395
+ public function testGetEnvKeyChained ()
396
+ {
397
+ $ processor = new EnvVarProcessor (new Container ());
398
+
399
+ $ this ->assertSame ('password ' , $ processor ->getEnv ('key ' , 'index:file:foo ' , function ($ name ) {
400
+ $ this ->assertSame ('file:foo ' , $ name );
401
+
402
+ return array (
403
+ 'index ' => 'password ' ,
404
+ );
405
+ }));
406
+ }
317
407
}
0 commit comments