Insert correct parameter_bag service in AbstractController

This commit is contained in:
Niels Keurentjes 2018-05-30 01:32:15 +02:00 committed by Nicolas Grekas
parent e0ec1f3a61
commit 37270d79a2
2 changed files with 28 additions and 1 deletions

View File

@ -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,
);
}

View File

@ -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')));