Reputation: 61
I want to use behat with symfony flex When i inject service in behat context file inside constructor, the autowire dont works. I need to explicitly configure service to public to use that service in behat. Is there another way to inject service in behat context file without making it public?
Here i am getting below error The "App\DataConsumer" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
behat.yml
default:
suites:
default:
contexts:
- FeatureContext:
kernel: '@kernel'
- ImageConsumerContext:
dataConsumer: '@App\DataConsumer'
Upvotes: 3
Views: 717
Reputation: 3166
UPDATE:
Starting from Symfony 4.1 it's allowed to fetch private services from tests.
The only remaining drawback of "private services by default" is that testing was harder than before. Some developers even defined some config in the test environment to make all services public in tests. In Symfony 4.1, we did the same and now tests allow fetching private services by default.
Source: https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing
You can make the service only public for your test environment.
In config/services_test.yaml
add:
services:
...
test.App\DataConsumer: '@App\DataConsumer'
Then in your behat.yml:
default:
suites:
default:
contexts:
- FeatureContext:
kernel: '@kernel'
- ImageConsumerContext:
dataConsumer: '@test.App\DataConsumer'
Upvotes: 1