Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] Allow MockHttpClient $responseFactory to be modifiable though accessors #40620

Copy link
Copy link
Closed
@rrajkomar

Description

@rrajkomar
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.