From 5489c7d3a7d282adee945f0e9ae0f437d80eaf4d Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 22 May 2025 01:20:12 +0200 Subject: [PATCH 1/2] Update ServicesAssertionsTrait.php: Adding another hint about private services If this setting is missing, `test.private_services_locator` isn't loaded. Just encountered this problem in one of my projects... --- src/Codeception/Module/Symfony/ServicesAssertionsTrait.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php b/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php index bd9140c0..1c14425a 100644 --- a/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php +++ b/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php @@ -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 * 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"); + Recommended 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 + Besides, `test` needs to be set to `true` in your `config/packages/framework.php`/`.yaml`, see https://symfony.com/doc/current/reference/configuration/framework.html#test"); } return $service; From 73d95dde9bf897d266ef8a00777b63fc83ed0e85 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 22 May 2025 21:08:47 +0200 Subject: [PATCH 2/2] Update ServicesAssertionsTrait.php --- src/Codeception/Module/Symfony/ServicesAssertionsTrait.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php b/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php index 1c14425a..fa26f3f3 100644 --- a/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php +++ b/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php @@ -24,9 +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.php`/`.yaml`, see https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private\n - Besides, `test` needs to be set to `true` in your `config/packages/framework.php`/`.yaml`, see https://symfony.com/doc/current/reference/configuration/framework.html#test"); + $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;