Skip to content

Commit 1d4cdae

Browse files
burned42Naktibalda
authored andcommitted
[Symfony] Make grabService use the special test service container if available (#5706)
grabService seems to be somewhat broken for newer Symfony versions (> 4.1 ?) and with Symfony 4.1 a special container can be accessed via `test.service_container` for testing purposes which also provides access to private services: https://symfony.com/doc/current/testing.html#accessing-the-container
1 parent 0b3eb2a commit 1d4cdae

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,17 @@ public function _getEntityManager()
265265
*/
266266
public function _getContainer()
267267
{
268-
return $this->kernel->getContainer();
268+
$container = $this->kernel->getContainer();
269+
270+
if (!($container instanceof ContainerInterface)) {
271+
$this->fail('Could not get Symfony container');
272+
}
273+
274+
if ($container->has('test.service_container')) {
275+
return $container->get('test.service_container');
276+
}
277+
278+
return $container;
269279
}
270280

271281
/**

0 commit comments

Comments
 (0)