Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[testing] tell about self::$container #9974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,30 @@ You can also get the objects related to the latest request::
Accessing the Container
~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 4.1

The ``self::$container`` property was introduced in Symfony 4.1.

It's highly recommended that a functional test only tests the response. But
under certain very rare circumstances, you might want to access some internal
objects to write assertions. In such cases, you can access the Dependency
Injection Container::
objects to write assertions. In such cases, you can access your services via
a special property on the test class. Because services are private by default,
this property holds a special container, which allows fetching public and all
non-removed private services::

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

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

.. tip::

The special container that gives access to private services exists only in
the ``test`` environment and is itself a service that you can accessed from
the real container using the ``test.service_container`` id.

.. tip::

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