Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle] Fix service reset between tests#58240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[FrameworkBundle] Fix service reset between tests#58240
Uh oh!
There was an error while loading.Please reload this page.
Conversation
...rameworkBundle/Tests/Functional/Bundle/TestBundle/TestServiceContainer/ResettableService.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/TestServiceContainer/services.yml OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
fad3d3e to549ada5CompareUh oh!
There was an error while loading.Please reload this page.
| if ($container->has('services_resetter')) { | ||
| $container->get('services_resetter')->reset(); | ||
| }elseif ($containerinstanceof ResetInterface) { | ||
| $container->reset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
$container->reset() must still be called, to reset the instances hold by the container itself (see the code of line 302).
Btw, if you ensure that theservices_resetter service is instantiated, the container reset call will then call it (as ServiceResetter implements the ResetInterface).
The reason it was not called is becauseContainer::reset only resetsinstantiated resettable services
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@stof Fixed, seehttps://github.com/symfony/symfony/compare/549ada5257c771da92d51aff76e224e1ac5d31f4..5491aa54a3205acfaf5ba62c134bddc26d794a36
Initially, I wanted to just instantiate theservices_resetter and letContainer::reset() call reset on it, but that didn’t work because theservices_resetter only resets instantiated services. Because of line 302, by the time it’s called, there aren’t any instantiated services left.
The downside of the current approach is that some services will get reset twice, but I don’t see a better solution at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ah indeed. The container resets itself before resetting the services.
I think this might actually be an issue if thereset method of a service triggers the instantiation of some other service. I think the resetting of the container state should probably be moved after the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
5491aa5 to53d0f56Compare53d0f56 tofb1ae1aComparexabbuh commentedSep 13, 2024
Isn’t the test failure on PHP 8.2 related? |
HypeMC commentedSep 13, 2024
@xabbuh Yes, but that's high-deps and if I'm not mistaking, that'll get resolved when merged upstream. |
nicolas-grekas commentedSep 16, 2024
Thank you@HypeMC. |
…nel is shut down (jderusse)This PR was merged into the 5.4 branch.Discussion----------[FrameworkBundle] Do not access the container when the kernel is shut down| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues | -| License | MIT#58240 play with the container after the kernel was shut down.This is an issue when the kernel performs a cleanup operation. For instance, the `@Nyholm` TestBundle [deletes cache files](https://github.com/SymfonyTest/symfony-bundle-test/blob/241bf0e2f00f28f7327113570ab20e24a5828829/src/TestKernel.php#L184-L199) as a result, the service is not accessible anymore and triggers errors.This PR move the call to `container->get` before `kernel::shutdown`Commits-------e68f88c [FrameworkBundle] Do not access the container when the kernel is shut down
Currently, not all services are reset between tests. If a service uses the kernel.reset tag but does not implement the ResetInterface, it never gets reset.