From b852cd0990c9d6a55b75a699b5e4efec40d85fc0 Mon Sep 17 00:00:00 2001 From: Gustavo Nieves Date: Fri, 4 Sep 2026 02:43:01 -0500 Subject: [PATCH 1/3] Add functional test for grabEntityManager() Cover grabEntityManager(), added in codeception/module-symfony: assert it returns an open EntityManagerInterface, and that it is the very instance the application uses rather than a copy, by comparing it against the doctrine.orm.default_entity_manager service. No app fixtures are needed: the existing User entity and its fixture cover it. The test is identical on every branch, since the method behaves the same on all supported Symfony versions. --- tests/Functional/DoctrineCest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Functional/DoctrineCest.php b/tests/Functional/DoctrineCest.php index cc54e0a..55c4b6a 100644 --- a/tests/Functional/DoctrineCest.php +++ b/tests/Functional/DoctrineCest.php @@ -8,9 +8,19 @@ use App\Repository\Model\UserRepositoryInterface; use App\Repository\UserRepository; use App\Tests\Support\FunctionalTester; +use Doctrine\ORM\EntityManagerInterface; final class DoctrineCest { + public function grabEntityManager(FunctionalTester $I): void + { + $em = $I->grabEntityManager(); + + $I->assertInstanceOf(EntityManagerInterface::class, $em); + $I->assertTrue($em->isOpen()); + $I->assertSame($em, $I->grabService('doctrine.orm.default_entity_manager')); + } + public function grabNumRecords(FunctionalTester $I) { $numRecords = $I->grabNumRecords(User::class); From 0d18b5e4d418951e1efc9979d2d8ccb367c35b7b Mon Sep 17 00:00:00 2001 From: Gustavo Nieves Date: Fri, 4 Sep 2026 02:43:33 -0500 Subject: [PATCH 2/3] Add functional test for resetDoctrineManager() Cover resetDoctrineManager(), added in codeception/module-symfony. Assert both halves of its contract: an open manager is only cleared, so a previously managed entity is no longer in the identity map, and a closed manager is reopened. The seeNumRecords() call at the end proves the transaction the Doctrine module opened for the test survived the reset. No app fixtures are needed: the test closes the manager itself rather than provoking a failed flush, which keeps it deterministic under settings.shuffle. The test is identical on every branch. The module recovers through Doctrine's registry where the entity manager service is lazy and by rebooting the kernel where it is not, but both paths are observable only as a reopened manager. --- tests/Functional/DoctrineCest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Functional/DoctrineCest.php b/tests/Functional/DoctrineCest.php index 55c4b6a..406e7b0 100644 --- a/tests/Functional/DoctrineCest.php +++ b/tests/Functional/DoctrineCest.php @@ -49,6 +49,22 @@ public function grabRepository(FunctionalTester $I) $I->assertInstanceOf(UserRepository::class, $repository); } + public function resetDoctrineManager(FunctionalTester $I): void + { + $em = $I->grabEntityManager(); + $user = $em->getRepository(User::class)->findOneBy(['email' => 'john_doe@gmail.com']); + $I->assertTrue($em->contains($user)); + + $I->resetDoctrineManager(); + $I->assertFalse($I->grabEntityManager()->contains($user)); + + $I->grabEntityManager()->close(); + $I->resetDoctrineManager(); + + $I->assertTrue($I->grabEntityManager()->isOpen()); + $I->seeNumRecords(1, User::class); + } + public function seeNumRecords(FunctionalTester $I) { $I->seeNumRecords(1, User::class); From 12f9682cde34885af0e912b896993fb70447b7f4 Mon Sep 17 00:00:00 2001 From: Gustavo Nieves Date: Fri, 4 Sep 2026 02:44:01 -0500 Subject: [PATCH 3/3] 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. --- tests/Functional/ServicesCest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Functional/ServicesCest.php b/tests/Functional/ServicesCest.php index c926ac2..0607c15 100644 --- a/tests/Functional/ServicesCest.php +++ b/tests/Functional/ServicesCest.php @@ -6,10 +6,23 @@ use App\Service\Greeting; use App\Tests\Support\FunctionalTester; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Security\Core\Security; final class ServicesCest { + public function grabContainer(FunctionalTester $I): void + { + $container = $I->grabContainer(); + + $I->assertInstanceOf(ContainerInterface::class, $container); + $I->assertSame('test', $container->getParameter('kernel.environment')); + + $I->assertTrue($container->has(EntityManagerInterface::class)); + $I->assertFalse($I->grabService('kernel')->getContainer()->has(EntityManagerInterface::class)); + } + public function grabService(FunctionalTester $I) { $security = $I->grabService('security.helper');