10000 [FrameworkBundle] fix Could not find service "test.service_container" by smilesrg · Pull Request #41719 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] fix Could not find service "test.service_container" #41719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bug #41715: [FrameworkBundle] Partial backport of PR#41530
  • Loading branch information
smilesrg committed Jun 15, 2021
commit 0748b5247e004f9991b3ceb38b7a1edf1a4e2d3b
20 changes: 13 additions & 7 deletions src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -83,7 +85,7 @@ public function getProfile()
*/
public function enableProfiler()
{
if ($this->kernel->getContainer()->has('profiler')) {
if ($this->getContainer()->has('profiler')) {
$this->profiler = true;
}
}
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = <<<EOF
Expand Down
0