diff --git a/Collector/ProfileClient.php b/Collector/ProfileClient.php index 2cb35930..ec0cc5fd 100644 --- a/Collector/ProfileClient.php +++ b/Collector/ProfileClient.php @@ -47,8 +47,8 @@ class ProfileClient implements HttpClient, HttpAsyncClient private $eventNames = []; /** - * @param HttpClient|HttpAsyncClient $client The client to profile. Client must implement both HttpClient and - * HttpAsyncClient interfaces. + * @param HttpClient|HttpAsyncClient $client The client to profile. Client must implement HttpClient or + * HttpAsyncClient interface. * @param Collector $collector * @param Formatter $formatter * @param Stopwatch $stopwatch @@ -56,14 +56,9 @@ class ProfileClient implements HttpClient, HttpAsyncClient public function __construct($client, Collector $collector, Formatter $formatter, Stopwatch $stopwatch) { if (!($client instanceof HttpClient && $client instanceof HttpAsyncClient)) { - throw new \RuntimeException(sprintf( - '%s first argument must implement %s and %s. Consider using %s.', - __METHOD__, - HttpClient::class, - HttpAsyncClient::class, - FlexibleHttpClient::class - )); + $client = new FlexibleHttpClient($client); } + $this->client = $client; $this->collector = $collector; $this->formatter = $formatter; diff --git a/Tests/Functional/Issue206.php b/Tests/Functional/Issue206.php new file mode 100644 index 00000000..881cc6ee --- /dev/null +++ b/Tests/Functional/Issue206.php @@ -0,0 +1,29 @@ +getContainer(); + PluginClientFactory::setFactory([$container->get('Http\Client\Common\PluginClientFactory'), 'createClient']); + + // Create a client + $myCustomClient = new HttpMethodsClient(HttpClientDiscovery::find(), MessageFactoryDiscovery::find()); + $pluginClient = (new PluginClientFactory())->createClient($myCustomClient, []); + + // If we get to this line, no exceptions has been thrown. + $this->assertInstanceOf(PluginClient::class, $pluginClient); + } +}