@@ -556,6 +556,54 @@ allows fetching both public and all non-removed private services::
556
556
For a list of services available in your application, use the ``debug:container ``
557
557
command.
558
558
559
+ If a private service is *never * used in your application (outside of your test),
560
+ it is *removed * from the container and cannot be accessed as described above. In
561
+ that case, you can create a public alias in the ``test `` environment and access
562
+ it via that alias:
563
+
564
+ .. configuration-block ::
565
+
566
+ .. code-block :: yaml
567
+
568
+ # config/services_test.yaml
569
+ services :
570
+ # access the service in your test via
571
+ # self::$container->get('test.App\Test\SomeTestHelper')
572
+ test.App\Test\SomeTestHelper :
573
+ # the id of the private service
8000
td>574
+ alias : ' App\Test\SomeTestHelper'
575
+ public : true
576
+
577
+ .. code-block :: xml
578
+
579
+ <!-- config/services_test.xml -->
580
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
581
+ <container xmlns =" http://symfony.com/schema/dic/services"
582
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
583
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
584
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
585
+
586
+ <services >
587
+ <!-- ... -->
588
+
589
+ <service id =" test.App\Test\SomeTestHelper" alias =" App\Test\SomeTestHelper" public =" true" />
590
+ </services >
591
+ </container >
592
+
593
+ .. code-block :: php
594
+
595
+ // config/services_test.php
596
+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
597
+
598
+ use App\Service\MessageGenerator;
599
+ use App\Updates\SiteUpdateManager;
600
+
601
+ return function(ContainerConfigurator $configurator) {
602
+ // ...
603
+
604
+ $services->alias('test.App\Test\SomeTestHelper', 'App\Test\SomeTestHelper')->public();
605
+ };
606
+
559
607
.. tip ::
560
608
561
609
The special container that gives access to private services exists only in
0 commit comments