Skip to content

Commit 1a9e936

Browse files
TavoNiievezclaude
andcommitted
Add functional test for grabContainer()
Cover grabContainer(), added in codeception/module-symfony: assert it returns the container for the test environment, and that it is the test container rather than the kernel's own. The last two assertions are the point of the method: the test container resolves a private service that the kernel container cannot see, which is what made the widespread grabService('kernel')->getContainer() workaround subtly wrong. No app fixtures are needed: EntityManagerInterface is registered as a private autowiring alias by doctrine-bundle on every branch. The test is identical on every branch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H9UKS58pxkiV3ovVP9J4tB
1 parent 8ea4d6d commit 1a9e936

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/Functional/ServicesCest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@
66

77
use App\Service\Greeting;
88
use App\Tests\Support\FunctionalTester;
9+
use Doctrine\ORM\EntityManagerInterface;
910
use Symfony\Bundle\SecurityBundle\Security;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
1012

1113
final class ServicesCest
1214
{
15+
public function grabContainer(FunctionalTester $I): void
16+
{
17+
$container = $I->grabContainer();
18+
19+
$I->assertInstanceOf(ContainerInterface::class, $container);
20+
$I->assertSame('test', $container->getParameter('kernel.environment'));
21+
22+
// Unlike the kernel's container, the test container also exposes private services.
23+
$I->assertTrue($container->has(EntityManagerInterface::class));
24+
$I->assertFalse($I->grabService('kernel')->getContainer()->has(EntityManagerInterface::class));
25+
}
26+
1327
public function grabService(FunctionalTester $I)
1428
{
1529
$security = $I->grabService('security.helper');

0 commit comments

Comments
 (0)