Conversation
…ontainer::set() change Symfony 6.4.34 refactored TestContainer::set() from a try/catch pattern to a proactive check using getPrivateContainer()->has(). In the old code (v6.4.31), Container::set() was called first, storing the mock in $container->services. It only fell back to $container->privates if an exception was thrown. In v6.4.34, the new code checks getPrivateContainer()->has() first. In the test environment, ALL services are registered in the private services locator, so mocks always end up in $container->privates — never reaching $container->services. Compiled service factories only resolve dependencies from $container->services, so they never see the mocks and create real service instances instead. This causes issues like infinite loops with real HTTP calls leading to OOM (6GB memory exhausted). The fix bypasses TestContainer::set() entirely by calling Container::set() directly on the public container via reflection on TestContainer::getPublicContainer(). This ensures mocks are stored in $container->services where compiled factories can find them.
2be70be to
e767a59
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.
Summary
Symfony 6.4.34 refactored
TestContainer::set()from a try/catch pattern to a proactive check, which broke mock injection for all services registered in the test private services locator.Old behavior (Symfony 6.4.31 — worked)
Container::set()was called first, storing the mock in$container->services. The fallback to$container->privatesonly happened if an exception was thrown (which it wasn't for these services).New behavior (Symfony 6.4.34 — broken)
The new code checks
getPrivateContainer()->has()first. In the test environment, all services are registered intest.private_services_locator, so mocks always go to$container->privates— never reaching$container->services.Impact
Compiled service factories only resolve dependencies from
$container->services, so they never see the mocks and create real service instances instead. This causes issues like infinite loops with real HTTP calls leading to OOM (6GB+ memory exhausted).Fix
Bypass
TestContainer::set()entirely by callingContainer::set()directly on the public container (accessed via reflection onTestContainer::getPublicContainer()). This ensures mocks are stored in$container->serviceswhere compiled factories can find them.