-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
codeception + symfony - New services cannot be grabbed #5828
Comments
I am not an expert in Symfony, but I think that your services could be private: https://symfony.com/doc/current/service_container.html#public-versus-private-services
# config/services.yaml
services:
# ... same code as before
# explicitly configure the service
Acme\PublicService:
public: true |
Probably you have some additional configuration for the test env in your Symfony app, by default https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing it should be accessible |
module-symfony uses some special test container, if it is available: Codeception/module-symfony@1d4cdae |
Hello, sorry for delayed answer. Services are not private (if they were private nothing would've fixed it except making them public). The problem seems to be the fact that if the service is not used anywhere (as is the case with first case in ttd methodology) it is not added at all in the container. I worked around the issue by just injecting the service in a dummy command but is... dirty. |
Adding hint about unused services not being available, see Codeception/Codeception#5828 and https://stackoverflow.com/a/63131476/1668200
As a "final" solution: Would it be possible that Codeception sets every service to |
more information about this. This bug related to 'all services as public' was described when Symfony 4.1 was released. # config/services_test.yaml
services:
_defaults:
public: true
# If you need to access services in a test, create an alias
# and then fetch that alias from the container. As a convention,
# aliases are prefixed with test. For example:
#
# test.App\Intangible\Service\MyService: '@App\Intangible\Service\MyService'
In the same way, the Symfony documentation suggests creating this file and making public the services that are required. I agree to add a more descriptive message, like the one suggested by @ThomasLandauer . |
Switching to *test* config, see Codeception/Codeception#5828 (comment)
@TavoNiievez I agree. Telling people what do to is enough - probably better than messing with their config ;-) I updated it to mention So once this gets merged, this issue can be closed. See also Codeception/module-symfony#21 |
* Update Symfony.php Adding hint about unused services not being available, see Codeception/Codeception#5828 and https://stackoverflow.com/a/63131476/1668200 * Update Symfony.php Switching to *test* config, see Codeception/Codeception#5828 (comment)
I have the following setup:
Symfony 5 project, with codeception 4.
I am trying to create a test for a newly created service. The problem is that I receive the error below when I try to test it.
The service code is below (is basically empty):
The test code is below (again, basically empty):
Integration tests yml:
I have tried to clear cache, recreate it etc. everything I could think of from cli, including (current path is project dir):
When I ran the test, same issue.
What did make it work, was to inject the service somewhere (for example in a controller), execute the controller, then use ./vendor/bin/codecept build. After I did those steps the test worked as expected. The obvious problem with this is that I am trying to create a pipeline for deploy where I raise a test environment (clean, on the fly before deploying to servers), run tests, and ensure everything is fine. Injecting all services somewhere just to be able to build is not an option (but I am opened to any cli options, including running most commands).
Even more strange is that after I did this, now the test works as expected even after I clean caches (var and _generated). Is like it would save something in a different place that I can't seem to find (can't find any relevant configs regarding this and google and bing fail me).
So... why is this happening, and how can I reliably make it work?
The text was updated successfully, but these errors were encountered: