diff --git a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php index 99f749e5fa7f7..638c71785ea01 100644 --- a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php +++ b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php @@ -49,7 +49,9 @@ public function __construct(KernelInterface $kernel, array $server = [], History */ public function getContainer() { - return $this->kernel->getContainer(); + $container = $this->kernel->getContainer(); + + return $container->has('test.service_container') ? $container->get('test.service_container') : $container; } /** @@ -69,11 +71,11 @@ public function getKernel() */ public function getProfile() { - if (null === $this->response || !$this->kernel->getContainer()->has('profiler')) { + if (null === $this->response || !$this->getContainer()->has('profiler')) { return false; } - return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->response); + return $this->getContainer()->get('profiler')->loadProfileFromResponse($this->response); } /** @@ -83,7 +85,7 @@ public function getProfile() */ public function enableProfiler() { - if ($this->kernel->getContainer()->has('profiler')) { + if ($this->getContainer()->has('profiler')) { $this->profiler = true; } } @@ -123,7 +125,7 @@ public function loginUser($user, string $firewallContext = 'main'): self $token = new TestBrowserToken($user->getRoles(), $user, $firewallContext); $token->setAuthenticated(true); - $container = $this->kernel->getContainer()->get('test.service_container'); + $container = $this->getContainer()->get('test.service_container'); $container->get('security.untracked_token_storage')->setToken($token); if (!$container->has('session')) { @@ -161,7 +163,7 @@ protected function doRequest($request) $this->profiler = false; $this->kernel->boot(); - $this->kernel->getContainer()->get('profiler')->enable(); + $this->getContainer()->get('profiler')->enable(); } return parent::doRequest($request); @@ -220,7 +222,11 @@ protected function getScript($request) $profilerCode = ''; if ($this->profiler) { - $profilerCode = '$kernel->getContainer()->get(\'profiler\')->enable();'; + $profilerCode = <<<'EOF' +$container = $kernel->getContainer(); +$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container; +$container->get('profiler')->enable(); +EOF; } $code = <<