Skip to content

[Testing] use static::getContainer() #15487

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
Jul 15, 2021
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
8 changes: 4 additions & 4 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Retrieving Services in the Test

In your integration tests, you often need to fetch the service from the
service container to call a specific method. After booting the kernel,
the container is stored in ``self::$container``::
the container is stored in ``static::getContainer()``::

// tests/Service/NewsletterGeneratorTest.php
namespace App\Tests\Service;
Expand All @@ -261,8 +261,8 @@ the container is stored in ``self::$container``::
// (1) boot the Symfony kernel
self::bootKernel();

// (2) use self::$container to access the service container
$container = self::$container;
// (2) use static::getContainer() to access the service container
$container = static::getContainer();

// (3) run some service & test the result
$newsletterGenerator = $container->get(NewsletterGenerator::class);
Expand All @@ -272,7 +272,7 @@ the container is stored in ``self::$container``::
}
}

The container in ``self::$container`` is actually a special test container.
The container in ``static::getContainer()`` is actually a special test container.
It gives you access to both the public services and the non-removed
:ref:`private services <container-public>` services.

Expand Down