Add functional tests for grabEntityManager(), resetDoctrineManager() and grabContainer() - #76
Merged
TavoNiievez merged 3 commits intoSep 4, 2026
Conversation
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.
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.
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.
TavoNiievez
force-pushed
the
test/entity-manager-and-container-accessors
branch
from
September 4, 2026 08:14
81f25e8 to
12f9682
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Covers the three accessors added in Codeception/module-symfony#248.
grabEntityManager()— asserts it returns an openEntityManagerInterface, and that it is the very instance the application uses rather than a copy, by comparing it againstdoctrine.orm.default_entity_manager.resetDoctrineManager()— asserts both halves of its contract: an open manager is only cleared, so a previously managed entity leaves the identity map; a closed one is reopened. The trailingseeNumRecords()proves the transaction the Doctrine module opened for the test survived the reset.grabContainer()— asserts it returns 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 widespreadgrabService('kernel')->getContainer()workaround subtly wrong.No app fixtures are needed. The reset test closes the manager itself instead of provoking a failed flush, which keeps it deterministic under
settings.shuffle.The four branch PRs are byte-identical apart from the
Securityimport that already differed per branch. The module recovers through Doctrine's registry where the entity manager service is lazy and by rebooting the kernel where it is not — Symfony 5.4 — but both paths are observable only as a reopened manager, so no version-gated variant is needed.These tests pass once
composer.lockpoints at amodule-symfonyrevision containing Codeception/module-symfony#248. Verified locally against that branch on Symfony 5.4 and 8.1: the fullFunctionalsuite is green.