File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -508,18 +508,30 @@ You can also get the objects related to the latest request::
508
508
Accessing the Container
509
509
~~~~~~~~~~~~~~~~~~~~~~~
510
510
511
+ .. versionadded :: 4.1
512
+
513
+ The ``self::$container `` property was introduced in Symfony 4.1.
514
+
511
515
It's highly recommended that a functional test only tests the response. But
512
516
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::
515
521
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
517
523
// $client->insulate() or using real HTTP requests to test your application
518
- $container = $client->getContainer() ;
524
+ $container = self::$container ;
519
525
520
526
For a list of services available in your application, use the ``debug:container ``
521
527
command.
522
528
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
+
523
535
.. tip ::
524
536
525
537
If the information you need to check is available from the profiler, use
You can’t perform that action at this time.
0 commit comments