Skip to content

Commit 67dd3c1

Browse files
mmenozzijaviereguiluz
authored andcommitted
Add tip about accessing removed services in the testing doc
1 parent 1a3f107 commit 67dd3c1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

testing.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,15 @@ allows fetching both public and all non-removed private services::
560560
For a list of services available in your application, use the ``debug:container``
561561
command.
562562

563+
.. tip::
564+
565+
Keep in mind that, if a private service is never used as a dependency of another service in
566+
your application, it is then removed from the container. So, if you try to access a private
567+
service in a test through the special test container and that service isn't used elsewhere
568+
you'll get a ``ServiceNotFoundException``. The solution, depending on the context, is to
569+
define the service as explicitly ``public`` or to inject it where you'll need it so Symfony
570+
doesn't remove it.
571+
563572
.. tip::
564573

565574
The special container that gives access to private services exists only in

0 commit comments

Comments
 (0)