8000 [HttpClient] Allow configure a Mock Response Factory for a specific HTTPClient · Issue #49995 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[HttpClient] Allow configure a Mock Response Factory for a specific HTTPClient #49995
Closed
@welcoMattic

Description

@welcoMattic

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.

cc @lyrixx @nicolas-grekas

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

      0