Skip to content

Commit 8ea4d6d

Browse files
TavoNiievezclaude
andcommitted
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. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H9UKS58pxkiV3ovVP9J4tB
1 parent 126a68c commit 8ea4d6d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/Functional/DoctrineCest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ public function grabRepository(FunctionalTester $I)
4949
$I->assertInstanceOf(UserRepository::class, $repository);
5050
}
5151

52+
public function resetDoctrineManager(FunctionalTester $I): void
53+
{
54+
$em = $I->grabEntityManager();
55+
$user = $em->getRepository(User::class)->findOneBy(['email' => 'john_doe@gmail.com']);
56+
$I->assertTrue($em->contains($user));
57+
58+
// An open manager is only cleared: the identity map is emptied.
59+
$I->resetDoctrineManager();
60+
$I->assertFalse($I->grabEntityManager()->contains($user));
61+
62+
// A closed manager is reopened, and the test transaction survives it.
63+
$I->grabEntityManager()->close();
64+
$I->resetDoctrineManager();
65+
66+
$I->assertTrue($I->grabEntityManager()->isOpen());
67+
$I->seeNumRecords(1, User::class);
68+
}
69+
5270
public function seeNumRecords(FunctionalTester $I)
5371
{
5472
$I->seeNumRecords(1, User::class);

0 commit comments

Comments
 (0)