-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
-
Hey, I have a a problem regarding scoped HTTP clients and my testing setup... I have configured a scope client like the following (replaced some sensitive data):
framework: http_client: scoped_clients: <some_service>.client: base_uri: '%env(<SOME_SERVICE>_URL)%'
This works as expected, however, I am having some issues with my tests. I get errors like these:
ServiceNotFoundException: The "<some_service>.client.uri_template" 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.
I've seen that issue before, so I thought that should be as easy as marking this service public (since using dependency injection is not really an option in my test setup):
when@test: services: <some_service>.client.uri_template: public: true
However, then I get the following error:
The definition for "<some_service>.client.uri_template" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.
But now I am a bit confused... I don't really know how this service is built under the hood, but the way I remember it, is that just marking that service as public
should not get rid of the class...
So my question is: how can I make that scoped HTTP client service public?
Beta Was this translation helpful? Give feedback.
All reactions
Ah, my bad, looks I have remembered that wrong... When defining services like this it indeed overrides the other stuff (like class
) as well... What needs to be done is to make a public alias to avoid that the service is removed from the container:
when@test:
services:
test.<some_service>.client:
alias: <some_service>.client
public: true
Replies: 2 comments 2 replies
-
Ah, my bad, looks I have remembered that wrong... When defining services like this it indeed overrides the other stuff (like class
) as well... What needs to be done is to make a public alias to avoid that the service is removed from the container:
when@test:
services:
test.<some_service>.client:
alias: <some_service>.client
public: true
Beta Was this translation helpful? Give feedback.
All reactions
-
In my case scoped client <some_service>.client is not autowiring to the service where it's required, which is the same in both dev and test environment.
Instead a new HttpClient is created and wired to it. And if I explicitly bind the argument, it throws the same error you mentioned.
ServiceNotFoundException: The "<some_service>.client.uri_template" 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.
What am I missing here?
Beta Was this translation helpful? Give feedback.
All reactions
-
If I am not mistaken, then the behavior you described is correct. Creating a scoped client will be another instance. So I am not sure why you would want to work around this.
Beta Was this translation helpful? Give feedback.
All reactions
-
By the another instance I meant a new client, which is not the scoped client that I created.
Beta Was this translation helpful? Give feedback.