Skip to content

Add functional tests for grabEntityManager(), resetDoctrineManager() and grabContainer() - #77

Merged
TavoNiievez merged 3 commits into
Codeception:6.4from
TavoNiievez:test/emc-6.4
Sep 4, 2026
Merged

Add functional tests for grabEntityManager(), resetDoctrineManager() and grabContainer()#77
TavoNiievez merged 3 commits into
Codeception:6.4from
TavoNiievez:test/emc-6.4

Conversation

@TavoNiievez

@TavoNiievez TavoNiievez commented Sep 4, 2026

Copy link
Copy Markdown
Member

Covers the three accessors added in Codeception/module-symfony#248.

  • grabEntityManager() — asserts it returns an open EntityManagerInterface, and that it is the very instance the application uses rather than a copy, by comparing it against doctrine.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 trailing seeNumRecords() 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 widespread grabService('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 Security import 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.lock points at a module-symfony revision containing Codeception/module-symfony#248. Verified locally against that branch on Symfony 5.4 and 8.1: the full Functional suite is green.

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
TavoNiievez merged commit 1a15b01 into Codeception:6.4 Sep 4, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant