@@ -490,6 +490,109 @@ public function testRequireFile()
490
490
$ this ->assertEquals ('foo ' , $ result );
491
491
}
492
492
493
+ /**
494
+ * @dataProvider validResolve
495
+ */
496
+ public function testGetEnvResolve ($ value , $ processed )
497
+ {
498
+ $ container = new ContainerBuilder ();
499
+ $ container ->setParameter ('bar ' , $ value );
500
+ $ container ->compile ();
501
+
502
+ $ processor = new EnvVarProcessor ($ container );
503
+
504
+ $ result = $ processor ->getEnv ('resolve ' , 'foo ' , function () {
505
+ return '%bar% ' ;
506
+ });
507
+
508
+ $ this ->assertSame ($ processed , $ result );
509
+ }
510
+
511
+ public function validResolve ()
512
+ {
513
+ return [
514
+ ['string ' , 'string ' ],
515
+ [1 , '1 ' ],
516
+ [1.1 , '1.1 ' ],
517
+ [true , '1 ' ],
518
+ [false , '' ],
519
+ ];
520
+ }
521
+
522
+ public function testGetEnvResolveNoMatch ()
523
+ {
524
+ $ processor = new EnvVarProcessor (new Container ());
525
+
526
+ $ result = $ processor ->getEnv ('resolve ' , 'foo ' , function () {
527
+ return '%% ' ;
528
+ });
529
+
530
+ $ this ->assertSame ('% ' , $ result );
531
+ }
532
+
533
+ /**
534
+ * @dataProvider notScalarResolve
535
+ */
536
+ public function testGetEnvResolveNotScalar ($ value )
537
+ {
538
+ $ this ->expectException (RuntimeException::class);
539
+ $ this ->expectExceptionMessage ('Parameter "bar" found when resolving env var "foo" must be scalar ' );
540
+
541
+ $ container = new ContainerBuilder ();
542
+ $ container ->setParameter ('bar ' , $ value );
543
+ $ container ->compile ();
544
+
545
+ $ processor = new EnvVarProcessor ($ container );
546
+
547
+ $ processor ->getEnv ('resolve ' , 'foo ' , function () {
548
+ return '%bar% ' ;
549
+ });
550
+ }
551
+
552
+ public function notScalarResolve ()
553
+ {
554
+ return [
555
+ [null ],
556
+ [[]],
557
+ ];
558
+ }
559
+
560
+ public function testGetEnvResolveNestedEnv ()
561
+ {
562
+ $ container = new ContainerBuilder ();
563
+ $ container ->setParameter ('env(BAR) ' , 'BAR in container ' );
564
+ $ container ->compile ();
565
+
566
+ $ processor = new EnvVarProcessor ($ container );
567
+ $ getEnv = \Closure::fromCallable ([$ processor , 'getEnv ' ]);
568
+
569
+ $ result = $ processor ->getEnv ('resolve ' , 'foo ' , function ($ name ) use ($ getEnv ) {
570
+ return 'foo ' === $ name ? '%env(BAR)% ' : $ getEnv ('string ' , $ name , function () {});
571
+ });
572
+
573
+ $ this ->assertSame ('BAR in container ' , $ result );
574
+ }
575
+
576
+ public function testGetEnvResolveNestedRealEnv ()
577
+ {
578
+ $ _ENV ['BAR ' ] = 'BAR in environment ' ;
579
+
580
+ $ container = new ContainerBuilder ();
581
+ $ container ->setParameter ('env(BAR) ' , 'BAR in container ' );
582
+ $ container ->compile ();
583
+
584
+ $ processor = new EnvVarProcessor ($ container );
585
+ $ getEnv = \Closure::fromCallable ([$ processor , 'getEnv ' ]);
586
+
587
+ $ result = $ processor ->getEnv ('resolve ' , 'foo ' , function ($ name ) use ($ getEnv ) {
588
+ return 'foo ' === $ name ? '%env(BAR)% ' : $ getEnv ('string ' , $ name , function () {});
589
+ });
590
+
591
+ $ this ->assertSame ('BAR in environment ' , $ result );
592
+
593
+ unset($ _ENV ['BAR ' ]);
594
+ }
595
+
493
596
/**
494
597
* @dataProvider validCsv
495
598
*/
0 commit comments