10000 minor #14819 Add warning about removed services (alexislefebvre) · symfony/symfony-docs@c9bad24 · GitHub
[go: up one dir, main page]

Skip to content

Commit c9bad24

Browse files
committed
minor #14819 Add warning about removed services (alexislefebvre)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- Add warning about removed services I was confused by the fact that the documentation explains: > Finally, for the most rare edge-cases, Symfony includes a special container which provides access to all services, public and private. This special container is a service that can be get via the normal container and the fact that the special container doesn't give access to the removed service. So I added a tip in the documentation, taking inspiration from a Symfony article: > Keep in mind that, because of how Symfony's service container work, unused services are removed from the container. This means that if you have a private service not used by any other service, Symfony will remove it and you won't be able to get it as explained in this article. The solution is to define the service as public explicitly so Symfony doesn't remove it. Source: https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing This is also consistent with the error message from Symfony: https://github.com/symfony/symfony/blob/3ffe5573e9dd045e157c6f17358c700fceae3feb/src/Symfony/Component/DependencyInjection/Container.php#L275 See also #12647 and symfony/symfony#30104 Commits ------- e6a6c33 Add warning about removed services
2 parents 09b30d5 + e6a6c33 commit c9bad24

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

testing.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ container is a service that can be get via the normal container::
590590
// ...
591591
}
592592

593+
.. caution::
594+
595+
The special container ``test.service_container`` doesn't give access
596+
to the services that have been removed. In this case, you'll have
597+
to declare the services you need as public.
598+
593599
.. tip::
594600

595601
If the information you need to check is available from the profiler, use

0 commit comments

Comments
 (0)
0