1414use Symfony \Bundle \FrameworkBundle \Tests \TestCase ;
1515use Symfony \Bundle \FrameworkBundle \Controller \ControllerTrait ;
1616use Symfony \Component \DependencyInjection \Container ;
17+ use Symfony \Component \DependencyInjection \ParameterBag \ContainerBag ;
18+ use Symfony \Component \DependencyInjection \ParameterBag \ContainerBagInterface ;
19+ use Symfony \Component \DependencyInjection \ParameterBag \FrozenParameterBag ;
1720use Symfony \Component \HttpFoundation \BinaryFileResponse ;
1821use Symfony \Component \HttpFoundation \File \File ;
1922use Symfony \Component \HttpFoundation \JsonResponse ;
@@ -528,6 +531,23 @@ public function testGetDoctrine()
528531
529532 $ this ->assertEquals ($ doctrine , $ controller ->getDoctrine ());
530533 }
534+
535+ public function testGetParameter ()
536+ {
537+ $ container = new Container (new FrozenParameterBag (array ('foo ' => 'bar ' )));
538+
539+ $ controller = $ this ->createController ();
540+ $ controller ->setContainer ($ container );
541+
542+ if (!interface_exists (ContainerBagInterface::class)) {
543+ $ this ->expectException (\LogicException::class);
544+ $ this ->expectExceptionMessage ('The "parameter_bag" service is not available. Try running "composer require dependency-injection:^4.1" ' );
545+ } else {
546+ $ container ->set ('parameter_bag ' , new ContainerBag ($ container ));
547+ }
548+
549+ $ this ->assertSame ('bar ' , $ controller ->getParameter ('foo ' ));
550+ }
531551}
532552
533553trait TestControllerTrait
@@ -552,5 +572,6 @@ trait TestControllerTrait
552572 createForm as public ;
553573 createFormBuilder as public ;
554574 getDoctrine as public ;
575+ getParameter as public ;
555576 }
556577}
0 commit comments