Skip to content

Update ServicesAssertionsTrait.php: Adding another hint about private… #210

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions src/Codeception/Module/Symfony/ServicesAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ trait ServicesAssertionsTrait
{
/**
* Grabs a service from the Symfony dependency injection container (DIC).
* In "test" environment, Symfony uses a special `test.service_container`.
* In the "test" environment, Symfony uses a special `test.service_container`.
* See the "[Public Versus Private Services](https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private)" documentation.
* Services that aren't injected somewhere into your app, need to be defined as `public` to be accessible by Codeception.
* Services that aren't injected anywhere in your app, need to be defined as `public` to be accessible by Codeception.
*
* ```php
* <?php
Expand All @@ -24,8 +24,10 @@ trait ServicesAssertionsTrait
public function grabService(string $serviceId): object
{
if (!$service = $this->getService($serviceId)) {
$this->fail("Service `{$serviceId}` is required by Codeception, but not loaded by Symfony since you're not using it anywhere in your app.\n
Recommended solution: Set it to `public` in your `config/services_test.php`/`.yaml`, see https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private");
$this->fail("Service `{$serviceId}` is required by Codeception, but not loaded by Symfony. Possible solutions:\n
In your `config/packages/framework.php`/`.yaml`, set `test` to `true` (when in test environment), see https://symfony.com/doc/current/reference/configuration/framework.html#test\n
If you're still getting this message, you're not using that service in your app, so Symfony isn't loading it at all.\n
Solution: Set it to `public` in your `config/services.php`/`.yaml`, see https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private\n");
}

return $service;
Expand Down
Loading