Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a026c67

Browse filesBrowse files
bug #41719 [FrameworkBundle] fix Could not find service "test.service_container" (smilesrg)
This PR was merged into the 5.2 branch. Discussion ---------- [FrameworkBundle] fix Could not find service "test.service_container" | Q | A | ------------- | --- | Branch? | 5.2, needs to be ported to 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #41715 | License | MIT Partial backport of #41530 Related to #41715 and #41530 When launching phpunit, got an error: `LogicException: Could not find service "test.service_container". Try updating the "framework.test" config to "true".` ``` There was 1 error: 1) App\Symfony\Bundle\Tests\Integration\IntegrationTest::testServiceWiringWithConfiguration LogicException: Could not find service "test.service_container". Try updating the "framework.test" config to "true". /Projects/app/vendor/symfony/framework-bundle/Test/KernelTestCase.php:109 /Projects/app/tests/integration/IntegrationTest.php:23 Caused by Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "test.service_container". Did you mean this: "service_container"? /Projects/app/vendor/symfony/dependency-injection/Container.php:280 /Projects/app/vendor/symfony/dependency-injection/Container.php:228 /Projects/app/vendor/symfony/framework-bundle/Test/KernelTestCase.php:107 /Projects/app/tests/integration/IntegrationTest.php:23 ``` /cc `@xabbuh` `@nicolas`-grekas Commits ------- 0748b52 bug #41715: [FrameworkBundle] Partial backport of PR#41530
2 parents 8b2ee31 + 0748b52 commit a026c67
Copy full SHA for a026c67

File tree

1 file changed

+13
-7
lines changed
Filter options

1 file changed

+13
-7
lines changed

‎src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php
+13-7Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public function __construct(KernelInterface $kernel, array $server = [], History
4949
*/
5050
public function getContainer()
5151
{
52-
return $this->kernel->getContainer();
52+
$container = $this->kernel->getContainer();
53+
54+
return $container->has('test.service_container') ? $container->get('test.service_container') : $container;
5355
}
5456

5557
/**
@@ -69,11 +71,11 @@ public function getKernel()
6971
*/
7072
public function getProfile()
7173
{
72-
if (null === $this->response || !$this->kernel->getContainer()->has('profiler')) {
74+
if (null === $this->response || !$this->getContainer()->has('profiler')) {
7375
return false;
7476
}
7577

76-
return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->response);
78+
return $this->getContainer()->get('profiler')->loadProfileFromResponse($this->response);
7779
}
7880

7981
/**
@@ -83,7 +85,7 @@ public function getProfile()
8385
*/
8486
public function enableProfiler()
8587
{
86-
if ($this->kernel->getContainer()->has('profiler')) {
88+
if ($this->getContainer()->has('profiler')) {
8789
$this->profiler = true;
8890
}
8991
}
@@ -123,7 +125,7 @@ public function loginUser($user, string $firewallContext = 'main'): self
123125
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
124126
$token->setAuthenticated(true);
125127

126-
$container = $this->kernel->getContainer()->get('test.service_container');
128+
$container = $this->getContainer()->get('test.service_container');
127129
$container->get('security.untracked_token_storage')->setToken($token);
128130

129131
if (!$container->has('session')) {
@@ -161,7 +163,7 @@ protected function doRequest($request)
161163
$this->profiler = false;
162164

163165
$this->kernel->boot();
164-
$this->kernel->getContainer()->get('profiler')->enable();
166+
$this->getContainer()->get('profiler')->enable();
165167
}
166168

167169
return parent::doRequest($request);
@@ -220,7 +222,11 @@ protected function getScript($request)
220222

221223
$profilerCode = '';
222224
if ($this->profiler) {
223-
$profilerCode = '$kernel->getContainer()->get(\'profiler\')->enable();';
225+
$profilerCode = <<<'EOF'
226+
$container = $kernel->getContainer();
227+
$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container;
228+
$container->get('profiler')->enable();
229+
EOF;
224230
}
225231

226232
$code = <<<EOF

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.