Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use framework.http_client.mock_response_factory #39266

Closed
Toflar opened this issue Dec 1, 2020 · 0 comments
Closed

Cannot use framework.http_client.mock_response_factory #39266

Toflar opened this issue Dec 1, 2020 · 0 comments

Comments

@Toflar
Copy link
Contributor

Toflar commented Dec 1, 2020

Symfony version(s) affected: 5.2.0

Description

Whenever I want to use the new framework.http_client.mock_response_factory option introduced in #35893, I get the following error:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service ".debug.http_client.inner".

How to reproduce

Configure

framework:
    test: true
    session:
        storage_id: session.storage.mock_file

    http_client:
        mock_response_factory: 'some_factory_id'

and let the container build.

Possible Solution

I think that's because the debug clients are only registered in the HttpClientPass which is excecuted after the extension.
Not really sure how this is supposed to work.

Moreover, I don't even see how that feature is supposed to work anyway:

if ($responseFactoryId = $config['mock_response_factory'] ?? null) {
$container->getDefinition($httpClientId)
->setClass(MockHttpClient::class)
->setArguments([new Reference($responseFactoryId)]);
}

How does setClass() help here? The http client services are created using the HttpClient::create() factory so without resetting the factory, this here cannot work?

Pinging @GaryPEGEOT as the original author of that feature, maybe I missed something completely :)

@Toflar Toflar added the Bug label Dec 1, 2020
GaryPEGEOT added a commit to GaryPEGEOT/symfony that referenced this issue Dec 1, 2020
GaryPEGEOT added a commit to GaryPEGEOT/symfony that referenced this issue Dec 1, 2020
nicolas-grekas added a commit that referenced this issue Dec 8, 2020
…or mock factory (GaryPEGEOT)

This PR was squashed before being merged into the 5.2 branch.

Discussion
----------

[HttpClient] Use decoration instead of class replacement for mock factory

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #39266
| License       | MIT

Commits
-------

9a9823c [HttpClient] Use decoration instead of class replacement for mock factory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants