diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ef0e487..e69fcb0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - Removed `message_factory`, `uri_factory`, and `stream_factory` classes config option. You can configure your own factories via psr17_*_factory classes config - Removed support for guzzle5-adapter - Removed support for Symfony versions <5.4 +- Changed the return type of `ClientFactory` to return a `ClientInterface` instead of `ClientInterface|HttpClient` +- Changed the type of `httplug.client.default` to `ClientInterface` instead of `HttpClient` +- Removed the `DummyClient` interface # Version 1 diff --git a/src/ClientFactory/AutoDiscoveryFactory.php b/src/ClientFactory/AutoDiscoveryFactory.php index 1c2bf5b9..ccad13e0 100644 --- a/src/ClientFactory/AutoDiscoveryFactory.php +++ b/src/ClientFactory/AutoDiscoveryFactory.php @@ -4,7 +4,7 @@ namespace Http\HttplugBundle\ClientFactory; -use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr18ClientDiscovery; /** * Use auto discovery to find a HTTP client. @@ -18,6 +18,6 @@ class AutoDiscoveryFactory implements ClientFactory */ public function createClient(array $config = []) { - return HttpClientDiscovery::find(); + return Psr18ClientDiscovery::find(); } } diff --git a/src/ClientFactory/ClientFactory.php b/src/ClientFactory/ClientFactory.php index 2d61af2f..9009c5c4 100644 --- a/src/ClientFactory/ClientFactory.php +++ b/src/ClientFactory/ClientFactory.php @@ -4,7 +4,6 @@ namespace Http\HttplugBundle\ClientFactory; -use Http\Client\HttpClient; use Psr\Http\Client\ClientInterface; /** @@ -13,9 +12,9 @@ interface ClientFactory { /** - * Input an array of configuration to be able to create a HttpClient. + * Input an array of configuration to be able to create a ClientInterface. * - * @return HttpClient|ClientInterface + * @return ClientInterface */ public function createClient(array $config = []); } diff --git a/src/ClientFactory/DummyClient.php b/src/ClientFactory/DummyClient.php deleted file mode 100644 index 09665e5e..00000000 --- a/src/ClientFactory/DummyClient.php +++ /dev/null @@ -1,19 +0,0 @@ - - */ -interface DummyClient extends HttpClient, HttpAsyncClient -{ -} diff --git a/src/Collector/PluginClientFactory.php b/src/Collector/PluginClientFactory.php index 85a2e2a3..17d8198c 100644 --- a/src/Collector/PluginClientFactory.php +++ b/src/Collector/PluginClientFactory.php @@ -7,7 +7,6 @@ use Http\Client\Common\Plugin; use Http\Client\Common\PluginClient; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; use Psr\Http\Client\ClientInterface; use Symfony\Component\Stopwatch\Stopwatch; @@ -44,9 +43,9 @@ public function __construct(Collector $collector, Formatter $formatter, Stopwatc } /** - * @param HttpClient|ClientInterface|HttpAsyncClient $client - * @param Plugin[] $plugins - * @param array $options { + * @param ClientInterface|HttpAsyncClient $client + * @param Plugin[] $plugins + * @param array $options { * * @var string $client_name to give client a name which may be used when displaying client information like in * the HTTPlugBundle profiler. diff --git a/src/Collector/ProfileClient.php b/src/Collector/ProfileClient.php index 191b2b44..ee4ec7ca 100644 --- a/src/Collector/ProfileClient.php +++ b/src/Collector/ProfileClient.php @@ -8,7 +8,6 @@ use Http\Client\Common\VersionBridgeClient; use Http\Client\Exception\HttpException; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -16,19 +15,19 @@ use Symfony\Component\Stopwatch\StopwatchEvent; /** - * The ProfileClient decorates any client that implement both HttpClient and HttpAsyncClient interfaces to gather target + * The ProfileClient decorates any client that implement both ClientInterface and HttpAsyncClient interfaces to gather target * url and response status code. * * @author Fabien Bourigault * * @internal */ -class ProfileClient implements HttpClient, HttpAsyncClient +class ProfileClient implements ClientInterface, HttpAsyncClient { use VersionBridgeClient; /** - * @var HttpClient|HttpAsyncClient + * @var ClientInterface|HttpAsyncClient */ private $client; @@ -55,12 +54,12 @@ class ProfileClient implements HttpClient, HttpAsyncClient private const STOPWATCH_CATEGORY = 'httplug'; /** - * @param HttpClient|HttpAsyncClient $client The client to profile. Client must implement HttpClient or - * HttpAsyncClient interface. + * @param ClientInterface|HttpAsyncClient $client The client to profile. Client must implement HttpClient or + * HttpAsyncClient interface. */ public function __construct($client, Collector $collector, Formatter $formatter, Stopwatch $stopwatch) { - if (!(($client instanceof ClientInterface || $client instanceof HttpClient) && $client instanceof HttpAsyncClient)) { + if (!($client instanceof ClientInterface && $client instanceof HttpAsyncClient)) { $client = new FlexibleHttpClient($client); } diff --git a/src/Collector/ProfileClientFactory.php b/src/Collector/ProfileClientFactory.php index 23d17fdc..8b68700c 100644 --- a/src/Collector/ProfileClientFactory.php +++ b/src/Collector/ProfileClientFactory.php @@ -6,7 +6,6 @@ use Http\Client\Common\FlexibleHttpClient; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; use Http\HttplugBundle\ClientFactory\ClientFactory; use Psr\Http\Client\ClientInterface; use Symfony\Component\Stopwatch\Stopwatch; @@ -61,7 +60,7 @@ public function createClient(array $config = []) { $client = is_callable($this->factory) ? call_user_func($this->factory, $config) : $this->factory->createClient($config); - if (!(($client instanceof HttpClient || $client instanceof ClientInterface) && $client instanceof HttpAsyncClient)) { + if (!($client instanceof ClientInterface && $client instanceof HttpAsyncClient)) { $client = new FlexibleHttpClient($client); } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 33337e72..3b4ead2f 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -112,7 +112,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->children() ->booleanNode('default_client_autowiring') ->defaultTrue() - ->info('Set to false to not autowire HttpClient and HttpAsyncClient.') + ->info('Set to false to not autowire ClientInterface and HttpAsyncClient.') ->end() ->arrayNode('main_alias') ->addDefaultsIfNotSet() diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index c37e8213..8c611914 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -13,7 +13,6 @@ use Http\Client\Common\PluginClient; use Http\Client\Common\PluginClientFactory; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; use Http\Client\Plugin\Vcr\RecordPlugin; use Http\Client\Plugin\Vcr\ReplayPlugin; use Http\Message\Authentication\BasicAuth; @@ -116,7 +115,7 @@ public function load(array $configs, ContainerBuilder $container): void if (!$config['default_client_autowiring']) { $container->removeAlias(HttpAsyncClient::class); - $container->removeAlias(HttpClient::class); + $container->removeAlias(ClientInterface::class); } if ($this->useVcrPlugin) { @@ -413,7 +412,6 @@ private function configureClient(ContainerBuilder $container, $clientName, array { $serviceId = 'httplug.client.'.$clientName; - $container->registerAliasForArgument($serviceId, HttpClient::class, $clientName); $container->registerAliasForArgument($serviceId, ClientInterface::class, $clientName); $container->registerAliasForArgument($serviceId, HttpAsyncClient::class, $clientName); @@ -440,7 +438,7 @@ private function configureClient(ContainerBuilder $container, $clientName, array if (empty($arguments['service'])) { $container - ->register($serviceId.'.client', HttpClient::class) + ->register($serviceId.'.client', ClientInterface::class) ->setFactory([new Reference($arguments['factory']), 'createClient']) ->addArgument($arguments['config']) ->setPublic(false); diff --git a/src/Discovery/ConfiguredClientsStrategy.php b/src/Discovery/ConfiguredClientsStrategy.php index 1739d7b6..24b0ebc4 100644 --- a/src/Discovery/ConfiguredClientsStrategy.php +++ b/src/Discovery/ConfiguredClientsStrategy.php @@ -5,9 +5,9 @@ namespace Http\HttplugBundle\Discovery; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; -use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr18ClientDiscovery; use Http\Discovery\Strategy\DiscoveryStrategy; +use Psr\Http\Client\ClientInterface; /** * A strategy that provide clients configured with HTTPlug bundle. With help from this strategy @@ -18,7 +18,7 @@ class ConfiguredClientsStrategy implements DiscoveryStrategy { /** - * @var HttpClient + * @var ClientInterface */ private static $client; @@ -28,14 +28,14 @@ class ConfiguredClientsStrategy implements DiscoveryStrategy private static $asyncClient; /** - * @param HttpClient $httpClient + * @param ClientInterface $httpClient * @param HttpAsyncClient $asyncClient */ - public function __construct(HttpClient $httpClient = null, HttpAsyncClient $asyncClient = null) + public function __construct(ClientInterface $httpClient = null, HttpAsyncClient $asyncClient = null) { self::$client = $httpClient; self::$asyncClient = $asyncClient; - HttpClientDiscovery::clearCache(); + Psr18ClientDiscovery::clearCache(); } /** @@ -43,7 +43,7 @@ public function __construct(HttpClient $httpClient = null, HttpAsyncClient $asyn */ public static function getCandidates($type) { - if (HttpClient::class === $type && null !== self::$client) { + if (ClientInterface::class === $type && null !== self::$client) { return [['class' => function () { return self::$client; }]]; diff --git a/src/Discovery/ConfiguredClientsStrategyListener.php b/src/Discovery/ConfiguredClientsStrategyListener.php index 82cefcd8..cca90968 100644 --- a/src/Discovery/ConfiguredClientsStrategyListener.php +++ b/src/Discovery/ConfiguredClientsStrategyListener.php @@ -4,7 +4,7 @@ namespace Http\HttplugBundle\Discovery; -use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr18ClientDiscovery; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -17,7 +17,7 @@ class ConfiguredClientsStrategyListener implements EventSubscriberInterface */ public function onEvent() { - HttpClientDiscovery::prependStrategy(ConfiguredClientsStrategy::class); + Psr18ClientDiscovery::prependStrategy(ConfiguredClientsStrategy::class); } /** diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index a0fe256b..70e40812 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -13,8 +13,8 @@ - - + + @@ -27,8 +27,8 @@ - - + + diff --git a/src/Resources/config/services_legacy.xml b/src/Resources/config/services_legacy.xml index b92221aa..99bda890 100644 --- a/src/Resources/config/services_legacy.xml +++ b/src/Resources/config/services_legacy.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + The "%alias_id%" service is deprecated in favor of using PSR-7 Psr\Http\Client\ClientInterface diff --git a/src/Resources/config/services_legacy_sf4.xml b/src/Resources/config/services_legacy_sf4.xml deleted file mode 100644 index 357c50c8..00000000 --- a/src/Resources/config/services_legacy_sf4.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - The "%alias_id%" service is deprecated in favor of using PSR-7 Psr\Http\Client\ClientInterface - - - diff --git a/tests/Functional/DiscoveredClientsTest.php b/tests/Functional/DiscoveredClientsTest.php index e4d3300a..518029b8 100644 --- a/tests/Functional/DiscoveredClientsTest.php +++ b/tests/Functional/DiscoveredClientsTest.php @@ -6,14 +6,14 @@ use Http\Adapter\Guzzle7\Client; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; use Http\Discovery\HttpAsyncClientDiscovery; -use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr18ClientDiscovery; use Http\Discovery\Strategy\CommonClassesStrategy; use Http\Discovery\Strategy\CommonPsr17ClassesStrategy; use Http\HttplugBundle\Collector\ProfileClient; use Http\HttplugBundle\Discovery\ConfiguredClientsStrategyListener; use Nyholm\NSA; +use Psr\Http\Client\ClientInterface; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class DiscoveredClientsTest extends WebTestCase @@ -26,7 +26,7 @@ public function testDiscoveredClient(): void $service = $container->get('httplug.auto_discovery.auto_discovered_client'); - $this->assertInstanceOf(HttpClient::class, $service); + $this->assertInstanceOf(ClientInterface::class, $service); } public function testDiscoveredAsyncClient(): void @@ -49,7 +49,7 @@ public function testDiscoveredClientWithProfilingEnabled(): void $service = $container->get('httplug.auto_discovery.auto_discovered_client'); $this->assertInstanceOf(ProfileClient::class, $service); - $this->assertInstanceOf(HttpClient::class, NSA::getProperty($service, 'client')); + $this->assertInstanceOf(ClientInterface::class, NSA::getProperty($service, 'client')); } public function testDiscoveredAsyncClientWithProfilingEnabled(): void @@ -81,7 +81,7 @@ public function testDiscovery(): void $httpAsyncClient = $container->get('httplug.auto_discovery.auto_discovered_async'); $this->assertInstanceOf(ProfileClient::class, $httpClient); - $this->assertSame(HttpClientDiscovery::find(), $httpClient); + $this->assertSame(Psr18ClientDiscovery::find(), $httpClient); $this->assertInstanceOf(ProfileClient::class, $httpAsyncClient); $this->assertSame(HttpAsyncClientDiscovery::find(), $httpAsyncClient); } @@ -115,7 +115,7 @@ public function testForcedDiscovery(): void $container->get('httplug.strategy'); - $this->assertEquals($container->get('httplug.client.acme'), HttpClientDiscovery::find()); + $this->assertEquals($container->get('httplug.client.acme'), Psr18ClientDiscovery::find()); $this->assertEquals($container->get('httplug.client.acme'), HttpAsyncClientDiscovery::find()); } @@ -132,7 +132,7 @@ protected function setUp(): void // Reset values $strategy = new ConfiguredClientsStrategyListener(null, null); - HttpClientDiscovery::setStrategies([CommonClassesStrategy::class, CommonPsr17ClassesStrategy::class]); + Psr18ClientDiscovery::setStrategies([CommonClassesStrategy::class, CommonPsr17ClassesStrategy::class]); $strategy->onEvent(); } } diff --git a/tests/Functional/DiscoveryTest.php b/tests/Functional/DiscoveryTest.php index d21d7410..0e7c824e 100644 --- a/tests/Functional/DiscoveryTest.php +++ b/tests/Functional/DiscoveryTest.php @@ -6,12 +6,12 @@ use Http\Adapter\Guzzle7\Client; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; -use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr18ClientDiscovery; use Http\HttplugBundle\DependencyInjection\HttplugExtension; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasAliasConstraint; use PHPUnit\Framework\Constraint\LogicalNot; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; @@ -44,7 +44,7 @@ public function testDiscoveryFallbacks(): void { $this->load(); - $this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class); + $this->assertContainerBuilderHasService('httplug.client.default', ClientInterface::class); $this->assertContainerBuilderHasService('httplug.psr17_request_factory.default', RequestFactoryInterface::class); $this->assertContainerBuilderHasService('httplug.psr17_response_factory.default', ResponseFactoryInterface::class); $this->assertContainerBuilderHasService('httplug.psr17_uri_factory.default', UriFactoryInterface::class); @@ -67,7 +67,7 @@ public function testDiscoveryPartialFallbacks(): void public function testNoDiscoveryFallbacks(): void { - $this->setDefinition('httplug.client.default', new Definition(HttpClient::class)); + $this->setDefinition('httplug.client.default', new Definition(ClientInterface::class)); $this->setDefinition('httplug.psr17_request_factory.default', new Definition(RequestFactoryInterface::class)); $this->setDefinition('httplug.psr17_uri_factory.default', new Definition(UriFactoryInterface::class)); $this->setDefinition('httplug.psr17_stream_factory.default', new Definition(StreamFactoryInterface::class)); @@ -75,9 +75,9 @@ public function testNoDiscoveryFallbacks(): void $this->load(); - $this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class); + $this->assertContainerBuilderHasService('httplug.client.default', ClientInterface::class); $clientDefinition = $this->container->getDefinition('httplug.client.default'); - $this->assertEquals([HttpClientDiscovery::class, 'find'], $clientDefinition->getFactory()); + $this->assertEquals([Psr18ClientDiscovery::class, 'find'], $clientDefinition->getFactory()); } public function testEnableAutowiring(): void @@ -88,7 +88,7 @@ public function testEnableAutowiring(): void $this->assertContainerBuilderHasService('httplug.client.default'); $this->assertContainerBuilderHasService('httplug.async_client.default'); - $this->assertContainerBuilderHasAlias(HttpClient::class); + $this->assertContainerBuilderHasAlias(ClientInterface::class); $this->assertContainerBuilderHasAlias(HttpAsyncClient::class); } @@ -107,7 +107,7 @@ public function testDisableAutowiring(): void self::assertThat( $this->container, - new LogicalNot(new ContainerBuilderHasAliasConstraint(HttpClient::class)) + new LogicalNot(new ContainerBuilderHasAliasConstraint(ClientInterface::class)) ); self::assertThat( $this->container, diff --git a/tests/Functional/Issue206.php b/tests/Functional/Issue206.php index bba21b64..4539cdbd 100644 --- a/tests/Functional/Issue206.php +++ b/tests/Functional/Issue206.php @@ -7,8 +7,8 @@ use Http\Client\Common\HttpMethodsClient; use Http\Client\Common\PluginClient; use Http\Client\Common\PluginClientFactory; -use Http\Discovery\HttpClientDiscovery; -use Http\Discovery\MessageFactoryDiscovery; +use Http\Discovery\Psr18ClientDiscovery; +use Nyholm\Psr7\Factory\Psr17Factory; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class Issue206 extends WebTestCase @@ -20,7 +20,7 @@ public function testCustomClientDoesNotCauseException(): void PluginClientFactory::setFactory([$container->get(PluginClientFactory::class), 'createClient']); // Create a client - $myCustomClient = new HttpMethodsClient(HttpClientDiscovery::find(), MessageFactoryDiscovery::find()); + $myCustomClient = new HttpMethodsClient(Psr18ClientDiscovery::find(), new Psr17Factory(), new Psr17Factory()); $pluginClient = (new PluginClientFactory())->createClient($myCustomClient, []); // If we get to this line, no exceptions has been thrown. diff --git a/tests/Functional/ProfilerTest.php b/tests/Functional/ProfilerTest.php index 9a4705d9..99975eb3 100644 --- a/tests/Functional/ProfilerTest.php +++ b/tests/Functional/ProfilerTest.php @@ -5,7 +5,7 @@ namespace Http\HttplugBundle\Tests\Functional; use GuzzleHttp\Psr7\Request; -use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class ProfilerTest extends WebTestCase @@ -18,7 +18,7 @@ public function testShowProfiler(): void $client = static::createClient(); $httpClient = $client->getContainer()->get('httplug.client.acme'); - assert($httpClient instanceof HttpClient); + assert($httpClient instanceof ClientInterface); $httpClient->sendRequest(new Request('GET', '/posts/1')); diff --git a/tests/Functional/ServiceInstantiationTest.php b/tests/Functional/ServiceInstantiationTest.php index 35dcfffa..37672ee4 100644 --- a/tests/Functional/ServiceInstantiationTest.php +++ b/tests/Functional/ServiceInstantiationTest.php @@ -8,7 +8,6 @@ use Http\Adapter\Guzzle7\Client; use Http\Client\Common\Plugin\RedirectPlugin; use Http\Client\Common\PluginClient; -use Http\Client\HttpClient; use Http\HttplugBundle\Collector\Collector; use Http\HttplugBundle\Collector\ProfileClient; use Http\HttplugBundle\Collector\ProfilePlugin; @@ -39,7 +38,7 @@ public function testHttpClient(): void $container = static::$kernel->getContainer(); $this->assertTrue($container->has('httplug.client')); $client = $container->get('httplug.client'); - $this->assertInstanceOf(HttpClient::class, $client); + $this->assertInstanceOf(ClientInterface::class, $client); } public function testHttpClientNoDebug(): void @@ -52,7 +51,7 @@ public function testHttpClientNoDebug(): void $container = static::$kernel->getContainer(); $this->assertTrue($container->has('httplug.client')); $client = $container->get('httplug.client'); - $this->assertInstanceOf(HttpClient::class, $client); + $this->assertInstanceOf(ClientInterface::class, $client); } /** diff --git a/tests/Unit/Collector/ProfileClientFactoryTest.php b/tests/Unit/Collector/ProfileClientFactoryTest.php index 4aeae247..75280322 100644 --- a/tests/Unit/Collector/ProfileClientFactoryTest.php +++ b/tests/Unit/Collector/ProfileClientFactoryTest.php @@ -4,13 +4,13 @@ namespace Http\HttplugBundle\Tests\Unit\Collector; -use Http\Client\HttpClient; use Http\HttplugBundle\ClientFactory\ClientFactory; use Http\HttplugBundle\Collector\Collector; use Http\HttplugBundle\Collector\Formatter; use Http\HttplugBundle\Collector\ProfileClient; use Http\HttplugBundle\Collector\ProfileClientFactory; use PHPUnit\Framework\TestCase; +use Psr\Http\Client\ClientInterface; use Symfony\Component\Stopwatch\Stopwatch; class ProfileClientFactoryTest extends TestCase @@ -31,7 +31,7 @@ class ProfileClientFactoryTest extends TestCase private $stopwatch; /** - * @var HttpClient + * @var ClientInterface */ private $client; @@ -40,7 +40,7 @@ public function setUp(): void $this->collector = $this->getMockBuilder(Collector::class)->disableOriginalConstructor()->getMock(); $this->formatter = $this->getMockBuilder(Formatter::class)->disableOriginalConstructor()->getMock(); $this->stopwatch = $this->getMockBuilder(Stopwatch::class)->getMock(); - $this->client = $this->getMockBuilder(HttpClient::class)->getMock(); + $this->client = $this->getMockBuilder(ClientInterface::class)->getMock(); } public function testCreateClientFromClientFactory(): void diff --git a/tests/Unit/Collector/ProfileClientTest.php b/tests/Unit/Collector/ProfileClientTest.php index a6db587a..b58d2340 100644 --- a/tests/Unit/Collector/ProfileClientTest.php +++ b/tests/Unit/Collector/ProfileClientTest.php @@ -8,7 +8,6 @@ use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Uri; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; use Http\HttplugBundle\Collector\Collector; use Http\HttplugBundle\Collector\Formatter; use Http\HttplugBundle\Collector\ProfileClient; @@ -18,6 +17,7 @@ use Http\Promise\RejectedPromise; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\UriInterface; @@ -37,7 +37,7 @@ class ProfileClientTest extends TestCase private $activeStack; /** - * @var HttpClient|MockObject + * @var CombinedClientInterface|MockObject */ private $client; @@ -95,7 +95,7 @@ public function setUp(): void { $this->collector = $this->getMockBuilder(Collector::class)->disableOriginalConstructor()->getMock(); $this->activeStack = new Stack('default', 'FormattedRequest'); - $this->client = $this->getMockBuilder(ClientInterface::class)->getMock(); + $this->client = $this->getMockBuilder(CombinedClientInterface::class)->getMock(); $this->uri = new Uri('https://example.com/target'); $this->request = new Request('GET', $this->uri); $this->formatter = $this->getMockBuilder(Formatter::class)->disableOriginalConstructor()->getMock(); @@ -240,6 +240,6 @@ public function testOnRejected(): void } } -interface ClientInterface extends HttpClient, HttpAsyncClient +interface CombinedClientInterface extends ClientInterface, HttpAsyncClient { } diff --git a/tests/Unit/DependencyInjection/HttplugExtensionTest.php b/tests/Unit/DependencyInjection/HttplugExtensionTest.php index 6f5a3696..b2895062 100644 --- a/tests/Unit/DependencyInjection/HttplugExtensionTest.php +++ b/tests/Unit/DependencyInjection/HttplugExtensionTest.php @@ -5,11 +5,11 @@ namespace Http\HttplugBundle\Tests\Unit\DependencyInjection; use Http\Adapter\Guzzle7\Client; -use Http\Client\HttpClient; use Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder; use Http\HttplugBundle\Collector\PluginClientFactoryListener; use Http\HttplugBundle\DependencyInjection\HttplugExtension; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; +use Psr\Http\Client\ClientInterface; use Symfony\Component\DependencyInjection\Reference; /** @@ -362,7 +362,7 @@ public function testUsingServiceKeyForClients(): void private function verifyProfilingDisabled(): void { $def = $this->container->findDefinition('httplug.client'); - $this->assertTrue(is_subclass_of($def->getClass(), HttpClient::class)); + $this->assertTrue(is_subclass_of($def->getClass(), ClientInterface::class)); $arguments = $def->getArguments(); if (isset($arguments[3])) { diff --git a/tests/Unit/Discovery/ConfiguredClientsStrategyTest.php b/tests/Unit/Discovery/ConfiguredClientsStrategyTest.php index ed3f44a7..b9abe22d 100644 --- a/tests/Unit/Discovery/ConfiguredClientsStrategyTest.php +++ b/tests/Unit/Discovery/ConfiguredClientsStrategyTest.php @@ -5,19 +5,19 @@ namespace Http\HttplugBundle\Tests\Unit\Discovery; use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; use Http\HttplugBundle\Discovery\ConfiguredClientsStrategy; use PHPUnit\Framework\TestCase; +use Psr\Http\Client\ClientInterface; class ConfiguredClientsStrategyTest extends TestCase { public function testGetCandidates(): void { - $httpClient = $this->getMockBuilder(HttpClient::class)->getMock(); + $httpClient = $this->getMockBuilder(ClientInterface::class)->getMock(); $httpAsyncClient = $this->getMockBuilder(HttpAsyncClient::class)->getMock(); $strategy = new ConfiguredClientsStrategy($httpClient, $httpAsyncClient); - $candidates = $strategy::getCandidates(HttpClient::class); + $candidates = $strategy::getCandidates(ClientInterface::class); $candidate = array_shift($candidates); $this->assertEquals($httpClient, $candidate['class']()); @@ -30,7 +30,7 @@ public function testGetCandidatesEmpty(): void { $strategy = new ConfiguredClientsStrategy(null, null); - $candidates = $strategy::getCandidates(HttpClient::class); + $candidates = $strategy::getCandidates(ClientInterface::class); $this->assertEquals([], $candidates); $candidates = $strategy::getCandidates(HttpAsyncClient::class); @@ -39,10 +39,10 @@ public function testGetCandidatesEmpty(): void public function testGetCandidatesEmptyAsync(): void { - $httpClient = $this->getMockBuilder(HttpClient::class)->getMock(); + $httpClient = $this->getMockBuilder(ClientInterface::class)->getMock(); $strategy = new ConfiguredClientsStrategy($httpClient, null); - $candidates = $strategy::getCandidates(HttpClient::class); + $candidates = $strategy::getCandidates(ClientInterface::class); $candidate = array_shift($candidates); $this->assertEquals($httpClient, $candidate['class']()); @@ -55,7 +55,7 @@ public function testGetCandidatesEmptySync(): void $httpAsyncClient = $this->getMockBuilder(HttpAsyncClient::class)->getMock(); $strategy = new ConfiguredClientsStrategy(null, $httpAsyncClient); - $candidates = $strategy::getCandidates(HttpClient::class); + $candidates = $strategy::getCandidates(ClientInterface::class); $this->assertEquals([], $candidates); $candidates = $strategy::getCandidates(HttpAsyncClient::class);