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

This commit is contained in:
Gary PEGEOT 2020-12-01 15:28:42 +01:00 committed by Nicolas Grekas
parent 42f440ec25
commit 9a9823c99a
2 changed files with 4 additions and 3 deletions

View File

@ -2071,8 +2071,8 @@ class FrameworkExtension extends Extension
}
if ($responseFactoryId = $config['mock_response_factory'] ?? null) {
$container->getDefinition($httpClientId)
->setClass(MockHttpClient::class)
$container->register($httpClientId.'.mock_client', MockHttpClient::class)
->setDecoratedService($httpClientId, null, -10) // lower priority than TraceableHttpClient
->setArguments([new Reference($responseFactoryId)]);
}
}

View File

@ -1611,7 +1611,7 @@ abstract class FrameworkExtensionTest extends TestCase
{
$container = $this->createContainerFromFile('http_client_mock_response_factory');
$definition = $container->getDefinition('http_client');
$definition = $container->getDefinition('http_client.mock_client');
$this->assertSame(MockHttpClient::class, $definition->getClass());
$this->assertCount(1, $definition->getArguments());
@ -1619,6 +1619,7 @@ abstract class FrameworkExtensionTest extends TestCase
$argument = $definition->getArgument(0);
$this->assertInstanceOf(Reference::class, $argument);
$this->assertSame('http_client', current($definition->getDecoratedService()));
$this->assertSame('my_response_factory', (string) $argument);
}