From 37270d79a2a72cfe9b1bfa5187cba72ba12402be Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Wed, 30 May 2018 01:32:15 +0200 Subject: [PATCH] Insert correct parameter_bag service in AbstractController --- .../Controller/AbstractController.php | 3 ++- .../Controller/AbstractControllerTest.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index 954961119e..b317786c68 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Controller; use Psr\Container\ContainerInterface; use Doctrine\Common\Persistence\ManagerRegistry; +use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -84,7 +85,7 @@ abstract class AbstractController implements ServiceSubscriberInterface 'form.factory' => '?'.FormFactoryInterface::class, 'security.token_storage' => '?'.TokenStorageInterface::class, 'security.csrf.token_manager' => '?'.CsrfTokenManagerInterface::class, - 'parameter_bag' => '?'.ContainerInterface::class, + 'parameter_bag' => '?'.ContainerBagInterface::class, 'message_bus' => '?'.MessageBusInterface::class, ); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php index 77e92a09c0..0ae42c14ce 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php @@ -24,6 +24,32 @@ class AbstractControllerTest extends ControllerTraitTest return new TestAbstractController(); } + /** + * This test protects the default subscribed core services against accidental modification. + */ + public function testSubscribedServices() + { + $subscribed = AbstractController::getSubscribedServices(); + $expectedServices = array( + 'router' => '?Symfony\\Component\\Routing\\RouterInterface', + 'request_stack' => '?Symfony\\Component\\HttpFoundation\\RequestStack', + 'http_kernel' => '?Symfony\\Component\\HttpKernel\\HttpKernelInterface', + 'serializer' => '?Symfony\\Component\\Serializer\\SerializerInterface', + 'session' => '?Symfony\\Component\\HttpFoundation\\Session\\SessionInterface', + 'security.authorization_checker' => '?Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface', + 'templating' => '?Symfony\\Component\\Templating\\EngineInterface', + 'twig' => '?Twig\\Environment', + 'doctrine' => '?Doctrine\\Common\\Persistence\\ManagerRegistry', + 'form.factory' => '?Symfony\\Component\\Form\\FormFactoryInterface', + 'parameter_bag' => '?Symfony\\Component\\DependencyInjection\\ParameterBag\\ContainerBagInterface', + 'message_bus' => '?Symfony\\Component\\Messenger\\MessageBusInterface', + 'security.token_storage' => '?Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface', + 'security.csrf.token_manager' => '?Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface', + ); + + $this->assertEquals($expectedServices, $subscribed, 'Subscribed core services in AbstractController have changed'); + } + public function testGetParameter() { $container = new Container(new FrozenParameterBag(array('foo' => 'bar')));