8000 [HttpClient] Use decoration instead of class replacement for mock fac… · symfony/symfony@9a9823c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a9823c

Browse files
GaryPEGEOTnicolas-grekas
authored andcommitted
[HttpClient] Use decoration instead of class replacement for mock factory
1 parent 42f440e commit 9a9823c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

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

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

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

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

1614-
$definition = $container->getDefinition('http_client');
1614+
$definition = $container->getDefinition('http_client.mock_client');
16151615

16161616
$this->assertSame(MockHttpClient::class, $definition->getClass());
16171617
$this->assertCount(1, $definition->getArguments());
16181618

16191619
$argument = $definition->getArgument(0);
16201620

16211621
$this->assertInstanceOf(Reference::class, $argument);
1622+
$this->assertSame('http_client', current($definition->getDecoratedService()));
16221623
$this->assertSame('my_response_factory', (string) $argument);
16231624
}
16241625

0 commit comments

Comments
 (0)
0