Description
Description
What I'm trying to achieve is the following : dynamically setting up a MockHttpClient replacement for the HttpClientInterface typehint inside my service when running Behat tests.
The idea is to be able to run a scenarii that will span the entire call stack (from the controller, all the way down to the HttpClient call and back) by setting the HttpClientInterface alias to a MockHttpClient service.
Each test should be able to define its own set of responses to be returned by the MockHttpClient upon call.
At the moment, this does not seem to be possible as the responseFactory needs to be injected into the MockHttpClient constructor and there are no accessors to change it afterwards.
It would be nice to be able to call a setResponseFactory from within a Behat test (or any other test type) to set the specific list of responses expected for the current test like this :
$mockHttpClient->setResponseFactory({My array of ResponseInterfaces});
[Note]
I try using in test environment the following without success
services:
_defaults:
autowire: true
autoconfigure: true
public: true
And in the behat test context
$this->kernel
->getContainer()
->set(HttpClientInterface::class, new MockHttpClient({My array of ResponseInterfaces}));
If there is a way to achieve this, without having to create specific classes for test purposes only, please share.