Skip to content

Commit 2cb5031

Browse files
bug #39268 [HttpClient] Use decoration instead of class replacement for 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 ------- 9a9823c99a [HttpClient] Use decoration instead of class replacement for mock factory
2 parents 05269f3 + 2345ff2 commit 2cb5031

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,8 +2069,8 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
20692069
}
20702070

20712071
if ($responseFactoryId = $config['mock_response_factory'] ?? null) {
2072-
$container->getDefinition($httpClientId)
2073-
->setClass(MockHttpClient::class)
2072+
$container->register($httpClientId.'.mock_client', MockHttpClient::class)
2073+
->setDecoratedService($httpClientId, null, -10) // lower priority than TraceableHttpClient
20742074
->setArguments([new Reference($responseFactoryId)]);
20752075
}
20762076
}

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,14 +1617,15 @@ public function testHttpClientMockResponseFactory()
16171617
{
16181618
$container = $this->createContainerFromFile('http_client_mock_response_factory');
16191619

1620-
$definition = $container->getDefinition('http_client');
1620+
$definition = $container->getDefinition('http_client.mock_client');
16211621

16221622
$this->assertSame(MockHttpClient::class, $definition->getClass());
16231623
$this->assertCount(1, $definition->getArguments());
16241624

16251625
$argument = $definition->getArgument(0);
16261626

16271627
$this->assertInstanceOf(Reference::class, $argument);
1628+
$this->assertSame('http_client', current($definition->getDecoratedService()));
16281629
$this->assertSame('my_response_factory', (string) $argument);
16291630
}
16301631

0 commit comments

Comments
 (0)