Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df4b2cb

Browse filesBrowse files
committed
minor #12647 Add tip about accessing removed services in the testing doc (mmenozzi, weaverryan)
This PR was submitted for the master branch but it was merged into the 4.4 branch instead (closes #12647). Discussion ---------- Add tip about accessing removed services in the testing doc As requested [here](symfony/symfony#30104 (comment)) this commit will add a tip about accessing removed services through the special test container in the testing docs. Commits ------- f038841 clarifying how to create a public alias for a test 67dd3c1 Add tip about accessing removed services in the testing doc
2 parents 1a3f107 + f038841 commit df4b2cb
Copy full SHA for df4b2cb

File tree

Expand file treeCollapse file tree

1 file changed

+50
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+50
-0
lines changed

‎testing.rst

Copy file name to clipboardExpand all lines: testing.rst
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,56 @@ 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+
If a private service is *never* used in your application (outside of your test), it
566+
is *removed* from the container and cannot be accessed as described above. In that
567+
case, you can create a public alias in the ``test`` environment and access it
568+
via that alias:
569+
570+
.. configuration-block::
571+
572+
.. code-block:: yaml
573+
574+
# config/services_test.yaml
575+
services:
576+
# access the service in your test via
577+
# self::$container->get('test.App\Test\SomeTestHelper')
578+
test.App\Test\SomeTestHelper:
579+
# the id of the private service
580+
alias: 'App\Test\SomeTestHelper'
581+
public: true
582+
583+
.. code-block:: xml
584+
585+
<!-- config/services_test.xml -->
586+
<?xml version="1.0" encoding="UTF-8" ?>
587+
<container xmlns="http://symfony.com/schema/dic/services"
588+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
589+
xsi:schemaLocation="http://symfony.com/schema/dic/services
590+
https://symfony.com/schema/dic/services/services-1.0.xsd">
591+
592+
<services>
593+
<!-- ... -->
594+
595+
<service id="test.App\Test\SomeTestHelper" alias="App\Test\SomeTestHelper" public="true"/>
596+
</services>
597+
</container>
598+
599+
.. code-block:: php
600+
601+
// config/services_test.php
602+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
603+
604+
use App\Service\MessageGenerator;
605+
use App\Updates\SiteUpdateManager;
606+
607+
return function(ContainerConfigurator $configurator) {
608+
// ...
609+
610+
$services->alias('test.App\Test\SomeTestHelper', 'App\Test\SomeTestHelper')->public();
611+
};
612+
563613
.. tip::
564614

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.