8000 minor #9974 [testing] tell about self::$container (nicolas-grekas) · symfony/symfony-docs@84fb473 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84fb473

Browse files
committed
minor #9974 [testing] tell about self::$container (nicolas-grekas)
This PR was merged into the 4.1 branch. Discussion ---------- [testing] tell about self::$container Fixes #9455. Same as https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing Commits ------- e64d89d [testing] tell about self::$container
2 parents 62e8b83 + e64d89d commit 84fb473

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

testing.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,18 +508,30 @@ You can also get the objects related to the latest request::
508508
Accessing the Container
509509
~~~~~~~~~~~~~~~~~~~~~~~
510510

511+
.. versionadded:: 4.1
512+
513+
The ``self::$container`` property was introduced in Symfony 4.1.
514+
511515
It's highly recommended that a functional test only tests the response. But
512516
under certain very rare circumstances, you might want to access some internal
513-
objects to write assertions. In such cases, you can access the Dependency
514-
Injection Container::
517+
objects to write assertions. In such cases, you can access your services via
518+
a special property on the test class. Because services are private by default,
519+
this property holds a special container, which allows fetching public and all
520+
non-removed private services::
515521

516-
// will be the same container used in your test, unless you're using
522+
// gives access to the same services used in your test, unless you're using
517523
// $client->insulate() or using real HTTP requests to test your application
518-
$container = $client->getContainer();
524+
$container = self::$container;
519525

520526
For a list of services available in your application, use the ``debug:container``
521527
command.
522528

529+
.. tip::
530+
531+
The special container that gives access to private services exists only in
532+
the ``test`` environment and is itself a service that you can accessed from
533+
the real container using the ``test.service_container`` id.
534+
523535
.. tip::
524536

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

0 commit comments

Comments
 (0)
0