Closed
Description
Description
Following #35893, which brings the possibility to configure a Mock Response Factory for all HTTP Clients of an application at once, we could consider to allow to set a Response Factory by default on each HTTP Client, in test
env only.
We could decorate every HTTP Client by default, with a MockHttpClient
. Then, we will be able to do something like:
self::getContainer->get('my.client')->setResponseFactory(fn () => new MockResponse);
self::getContainer->get('my.other.client')->setResponseFactory(fn () => new MockResponse);
self::getContainer->get('my.third.client')->request('GET', ....): // Here, we use the real client
It could be useful in case of need to mock only a particular HTTP Client, and leave the other ones making real HTTP requests. In my case, I use https://github.com/stoplightio/prism to serve mocked APIs, which are consumed by real HTTP Client in my app. But for some particular use cases, I need to mock the HTTP Client itself.