From 5e746fb22f8df94e2e558a65be4d1977979a5aa0 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 19 Nov 2018 12:13:41 +0100 Subject: [PATCH 01/14] Add types where possible --- src/BatchClient.php | 2 +- src/BatchResult.php | 20 ++++++++++---------- src/Deferred.php | 8 ++++++-- src/FlexibleHttpClient.php | 1 + src/HttpAsyncClientDecorator.php | 1 + src/HttpClientPool.php | 2 +- src/HttpClientPool/LeastUsedClientPool.php | 2 +- src/HttpClientPool/RandomClientPool.php | 2 +- src/HttpClientPool/RoundRobinClientPool.php | 2 +- src/HttpClientRouter.php | 2 +- src/HttpMethodsClient.php | 18 +++++++++--------- src/Plugin/ContentTypePlugin.php | 6 +++--- src/Plugin/CookiePlugin.php | 2 +- src/Plugin/ErrorPlugin.php | 2 +- src/Plugin/HeaderAppendPlugin.php | 2 +- src/Plugin/HeaderSetPlugin.php | 2 +- src/Plugin/RedirectPlugin.php | 2 +- src/PluginClient.php | 4 ++-- src/PluginClientFactory.php | 2 +- 19 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/BatchClient.php b/src/BatchClient.php index 2a39904..2889c81 100644 --- a/src/BatchClient.php +++ b/src/BatchClient.php @@ -52,7 +52,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface * BatchResult with a map of request to result for success, request to * exception for failures */ - public function sendRequests(array $requests) + public function sendRequests(array $requests): BatchResult { $batchResult = new BatchResult(); diff --git a/src/BatchResult.php b/src/BatchResult.php index 710611d..2286102 100644 --- a/src/BatchResult.php +++ b/src/BatchResult.php @@ -34,7 +34,7 @@ public function __construct() * * @return bool */ - public function hasResponses() + public function hasResponses(): bool { return $this->responses->count() > 0; } @@ -44,7 +44,7 @@ public function hasResponses() * * @return ResponseInterface[] */ - public function getResponses() + public function getResponses(): array { $responses = []; @@ -62,7 +62,7 @@ public function getResponses() * * @return bool */ - public function isSuccessful(RequestInterface $request) + public function isSuccessful(RequestInterface $request): bool { return $this->responses->contains($request); } @@ -76,7 +76,7 @@ public function isSuccessful(RequestInterface $request) * * @throws \UnexpectedValueException If request was not part of the batch or failed */ - public function getResponseFor(RequestInterface $request) + public function getResponseFor(RequestInterface $request): ResponseInterface { try { return $this->responses[$request]; @@ -93,7 +93,7 @@ public function getResponseFor(RequestInterface $request) * * @return BatchResult the new BatchResult with this request-response pair added to it */ - public function addResponse(RequestInterface $request, ResponseInterface $response) + public function addResponse(RequestInterface $request, ResponseInterface $response): BatchResult { $new = clone $this; $new->responses->attach($request, $response); @@ -106,7 +106,7 @@ public function addResponse(RequestInterface $request, ResponseInterface $respon * * @return bool */ - public function hasExceptions() + public function hasExceptions(): bool { return $this->exceptions->count() > 0; } @@ -116,7 +116,7 @@ public function hasExceptions() * * @return Exception[] */ - public function getExceptions() + public function getExceptions(): array { $exceptions = []; @@ -134,7 +134,7 @@ public function getExceptions() * * @return bool */ - public function isFailed(RequestInterface $request) + public function isFailed(RequestInterface $request): bool { return $this->exceptions->contains($request); } @@ -148,7 +148,7 @@ public function isFailed(RequestInterface $request) * * @throws \UnexpectedValueException If request was not part of the batch or was successful */ - public function getExceptionFor(RequestInterface $request) + public function getExceptionFor(RequestInterface $request): Exception { try { return $this->exceptions[$request]; @@ -165,7 +165,7 @@ public function getExceptionFor(RequestInterface $request) * * @return BatchResult the new BatchResult with this request-exception pair added to it */ - public function addException(RequestInterface $request, Exception $exception) + public function addException(RequestInterface $request, Exception $exception): BatchResult { $new = clone $this; $new->exceptions->attach($request, $exception); diff --git a/src/Deferred.php b/src/Deferred.php index 075a30e..952190d 100644 --- a/src/Deferred.php +++ b/src/Deferred.php @@ -34,7 +34,7 @@ public function __construct(callable $waitCallback) /** * {@inheritdoc} */ - public function then(callable $onFulfilled = null, callable $onRejected = null) + public function then(callable $onFulfilled = null, callable $onRejected = null): Promise { $deferred = new self($this->waitCallback); @@ -69,13 +69,15 @@ public function then(callable $onFulfilled = null, callable $onRejected = null) /** * {@inheritdoc} */ - public function getState() + public function getState(): string { return $this->state; } /** * Resolve this deferred with a Response. + * + * @param ResponseInterface $response */ public function resolve(ResponseInterface $response) { @@ -93,6 +95,8 @@ public function resolve(ResponseInterface $response) /** * Reject this deferred with an Exception. + * + * @param Exception $exception */ public function reject(Exception $exception) { diff --git a/src/FlexibleHttpClient.php b/src/FlexibleHttpClient.php index 58f8813..e731f8c 100644 --- a/src/FlexibleHttpClient.php +++ b/src/FlexibleHttpClient.php @@ -4,6 +4,7 @@ use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; /** * A flexible http client, which implements both interface and will emulate diff --git a/src/HttpAsyncClientDecorator.php b/src/HttpAsyncClientDecorator.php index 6eb576c..3e82c75 100644 --- a/src/HttpAsyncClientDecorator.php +++ b/src/HttpAsyncClientDecorator.php @@ -3,6 +3,7 @@ namespace Http\Client\Common; use Http\Client\HttpAsyncClient; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** diff --git a/src/HttpClientPool.php b/src/HttpClientPool.php index 6f4597f..90a8464 100644 --- a/src/HttpClientPool.php +++ b/src/HttpClientPool.php @@ -40,7 +40,7 @@ public function addHttpClient($client) * * @return HttpClientPoolItem Return a http client that can do both sync or async */ - abstract protected function chooseHttpClient(); + abstract protected function chooseHttpClient(): HttpClientPoolItem; /** * {@inheritdoc} diff --git a/src/HttpClientPool/LeastUsedClientPool.php b/src/HttpClientPool/LeastUsedClientPool.php index 6299cce..61eb670 100644 --- a/src/HttpClientPool/LeastUsedClientPool.php +++ b/src/HttpClientPool/LeastUsedClientPool.php @@ -18,7 +18,7 @@ final class LeastUsedClientPool extends HttpClientPool /** * {@inheritdoc} */ - protected function chooseHttpClient() + protected function chooseHttpClient(): HttpClientPoolItem { $clientPool = array_filter($this->clientPool, function (HttpClientPoolItem $clientPoolItem) { return !$clientPoolItem->isDisabled(); diff --git a/src/HttpClientPool/RandomClientPool.php b/src/HttpClientPool/RandomClientPool.php index 3255f86..2889ed7 100644 --- a/src/HttpClientPool/RandomClientPool.php +++ b/src/HttpClientPool/RandomClientPool.php @@ -16,7 +16,7 @@ final class RandomClientPool extends HttpClientPool /** * {@inheritdoc} */ - protected function chooseHttpClient() + protected function chooseHttpClient(): HttpClientPoolItem { $clientPool = array_filter($this->clientPool, function (HttpClientPoolItem $clientPoolItem) { return !$clientPoolItem->isDisabled(); diff --git a/src/HttpClientPool/RoundRobinClientPool.php b/src/HttpClientPool/RoundRobinClientPool.php index 8d8e40a..fe33c37 100644 --- a/src/HttpClientPool/RoundRobinClientPool.php +++ b/src/HttpClientPool/RoundRobinClientPool.php @@ -15,7 +15,7 @@ final class RoundRobinClientPool extends HttpClientPool /** * {@inheritdoc} */ - protected function chooseHttpClient() + protected function chooseHttpClient(): HttpClientPoolItem { $last = current($this->clientPool); diff --git a/src/HttpClientRouter.php b/src/HttpClientRouter.php index fa32c56..ac7699c 100644 --- a/src/HttpClientRouter.php +++ b/src/HttpClientRouter.php @@ -62,7 +62,7 @@ public function addClient($client, RequestMatcher $requestMatcher) * * @return HttpClient|HttpAsyncClient */ - protected function chooseHttpClient(RequestInterface $request) + private function chooseHttpClient(RequestInterface $request) { foreach ($this->clients as $client) { if ($client['matcher']->matches($request)) { diff --git a/src/HttpMethodsClient.php b/src/HttpMethodsClient.php index 0ec1e14..053fdea 100644 --- a/src/HttpMethodsClient.php +++ b/src/HttpMethodsClient.php @@ -56,7 +56,7 @@ public function __construct(HttpClient $httpClient, RequestFactory $requestFacto * * @return ResponseInterface */ - public function get($uri, array $headers = []) + public function get($uri, array $headers = []): ResponseInterface { return $this->send('GET', $uri, $headers, null); } @@ -71,7 +71,7 @@ public function get($uri, array $headers = []) * * @return ResponseInterface */ - public function head($uri, array $headers = []) + public function head($uri, array $headers = []): ResponseInterface { return $this->send('HEAD', $uri, $headers, null); } @@ -86,7 +86,7 @@ public function head($uri, array $headers = []) * * @return ResponseInterface */ - public function trace($uri, array $headers = []) + public function trace($uri, array $headers = []): ResponseInterface { return $this->send('TRACE', $uri, $headers, null); } @@ -102,7 +102,7 @@ public function trace($uri, array $headers = []) * * @return ResponseInterface */ - public function post($uri, array $headers = [], $body = null) + public function post($uri, array $headers = [], $body = null): ResponseInterface { return $this->send('POST', $uri, $headers, $body); } @@ -118,7 +118,7 @@ public function post($uri, array $headers = [], $body = null) * * @return ResponseInterface */ - public function put($uri, array $headers = [], $body = null) + public function put($uri, array $headers = [], $body = null): ResponseInterface { return $this->send('PUT', $uri, $headers, $body); } @@ -134,7 +134,7 @@ public function put($uri, array $headers = [], $body = null) * * @return ResponseInterface */ - public function patch($uri, array $headers = [], $body = null) + public function patch($uri, array $headers = [], $body = null): ResponseInterface { return $this->send('PATCH', $uri, $headers, $body); } @@ -150,7 +150,7 @@ public function patch($uri, array $headers = [], $body = null) * * @return ResponseInterface */ - public function delete($uri, array $headers = [], $body = null) + public function delete($uri, array $headers = [], $body = null): ResponseInterface { return $this->send('DELETE', $uri, $headers, $body); } @@ -166,7 +166,7 @@ public function delete($uri, array $headers = [], $body = null) * * @return ResponseInterface */ - public function options($uri, array $headers = [], $body = null) + public function options($uri, array $headers = [], $body = null): ResponseInterface { return $this->send('OPTIONS', $uri, $headers, $body); } @@ -183,7 +183,7 @@ public function options($uri, array $headers = [], $body = null) * * @return ResponseInterface */ - public function send($method, $uri, array $headers = [], $body = null) + public function send($method, $uri, array $headers = [], $body = null): ResponseInterface { return $this->sendRequest($this->requestFactory->createRequest( $method, diff --git a/src/Plugin/ContentTypePlugin.php b/src/Plugin/ContentTypePlugin.php index 8ef1d62..4bae01b 100644 --- a/src/Plugin/ContentTypePlugin.php +++ b/src/Plugin/ContentTypePlugin.php @@ -22,14 +22,14 @@ final class ContentTypePlugin implements Plugin * true skip the content type detection * false detect the content type (default value) */ - protected $skipDetection; + private $skipDetection; /** * Determine the size stream limit for which the detection as to be skipped (default to 16Mb). * * @var int */ - protected $sizeLimit; + private $sizeLimit; /** * @param array $config { @@ -96,7 +96,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl * * @return bool */ - private function isJson($stream) + private function isJson($stream): bool { $stream->rewind(); diff --git a/src/Plugin/CookiePlugin.php b/src/Plugin/CookiePlugin.php index 523628f..691d506 100644 --- a/src/Plugin/CookiePlugin.php +++ b/src/Plugin/CookiePlugin.php @@ -103,7 +103,7 @@ private function createCookie(RequestInterface $request, $setCookie) $parts = array_map('trim', explode(';', $setCookie)); if (empty($parts) || !strpos($parts[0], '=')) { - return; + return null; } list($name, $cookieValue) = $this->createValueKey(array_shift($parts)); diff --git a/src/Plugin/ErrorPlugin.php b/src/Plugin/ErrorPlugin.php index bcc1c67..3932121 100644 --- a/src/Plugin/ErrorPlugin.php +++ b/src/Plugin/ErrorPlugin.php @@ -66,7 +66,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl * * @return ResponseInterface If status code is not in 4xx or 5xx return response */ - protected function transformResponseToException(RequestInterface $request, ResponseInterface $response) + private function transformResponseToException(RequestInterface $request, ResponseInterface $response): ResponseInterface { if (!$this->onlyServerException && $response->getStatusCode() >= 400 && $response->getStatusCode() < 500) { throw new ClientErrorException($response->getReasonPhrase(), $request, $response); diff --git a/src/Plugin/HeaderAppendPlugin.php b/src/Plugin/HeaderAppendPlugin.php index 26fd813..86f9a1d 100644 --- a/src/Plugin/HeaderAppendPlugin.php +++ b/src/Plugin/HeaderAppendPlugin.php @@ -21,7 +21,7 @@ final class HeaderAppendPlugin implements Plugin /** * @var array */ - private $headers = []; + private $headers; /** * @param array $headers Hashmap of header name to header value diff --git a/src/Plugin/HeaderSetPlugin.php b/src/Plugin/HeaderSetPlugin.php index 75f11d4..f9723f0 100644 --- a/src/Plugin/HeaderSetPlugin.php +++ b/src/Plugin/HeaderSetPlugin.php @@ -17,7 +17,7 @@ final class HeaderSetPlugin implements Plugin /** * @var array */ - private $headers = []; + private $headers; /** * @param array $headers Hashmap of header name to header value diff --git a/src/Plugin/RedirectPlugin.php b/src/Plugin/RedirectPlugin.php index d2f442e..dce9995 100644 --- a/src/Plugin/RedirectPlugin.php +++ b/src/Plugin/RedirectPlugin.php @@ -218,7 +218,7 @@ protected function buildRedirectRequest(RequestInterface $request, UriInterface * * @return UriInterface */ - private function createUri(ResponseInterface $response, RequestInterface $request) + private function createUri(ResponseInterface $response, RequestInterface $request): UriInterface { if ($this->redirectCodes[$response->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$response->hasHeader('Location'))) { throw new MultipleRedirectionException('Cannot choose a redirection', $request, $response); diff --git a/src/PluginClient.php b/src/PluginClient.php index 7413152..a0e788b 100644 --- a/src/PluginClient.php +++ b/src/PluginClient.php @@ -107,7 +107,7 @@ public function sendAsyncRequest(RequestInterface $request) * * @return array */ - private function configure(array $options = []) + private function configure(array $options = []): array { if (isset($options['debug_plugins'])) { @trigger_error('The "debug_plugins" option is deprecated since 1.5 and will be removed in 2.0.', E_USER_DEPRECATED); @@ -143,7 +143,7 @@ private function configure(array $options = []) * * @return callable */ - private function createPluginChain($pluginList, callable $clientCallable) + private function createPluginChain(array $pluginList, callable $clientCallable): callable { $firstCallable = $lastCallable = $clientCallable; diff --git a/src/PluginClientFactory.php b/src/PluginClientFactory.php index bd4c08f..c980f4f 100644 --- a/src/PluginClientFactory.php +++ b/src/PluginClientFactory.php @@ -47,7 +47,7 @@ public static function setFactory(callable $factory) * * @return PluginClient */ - public function createClient($client, array $plugins = [], array $options = []) + public function createClient($client, array $plugins = [], array $options = []): PluginClient { if (static::$factory) { $factory = static::$factory; From 96b6fea54c15ae4b71c25d7970992da6d8fd21ad Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 19 Nov 2018 22:50:29 +0100 Subject: [PATCH 02/14] Fix CS --- src/BatchResult.php | 4 ++-- src/Deferred.php | 4 ++-- src/FlexibleHttpClient.php | 1 - src/HttpAsyncClientDecorator.php | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/BatchResult.php b/src/BatchResult.php index 2286102..97cb55b 100644 --- a/src/BatchResult.php +++ b/src/BatchResult.php @@ -93,7 +93,7 @@ public function getResponseFor(RequestInterface $request): ResponseInterface * * @return BatchResult the new BatchResult with this request-response pair added to it */ - public function addResponse(RequestInterface $request, ResponseInterface $response): BatchResult + public function addResponse(RequestInterface $request, ResponseInterface $response): self { $new = clone $this; $new->responses->attach($request, $response); @@ -165,7 +165,7 @@ public function getExceptionFor(RequestInterface $request): Exception * * @return BatchResult the new BatchResult with this request-exception pair added to it */ - public function addException(RequestInterface $request, Exception $exception): BatchResult + public function addException(RequestInterface $request, Exception $exception): self { $new = clone $this; $new->exceptions->attach($request, $exception); diff --git a/src/Deferred.php b/src/Deferred.php index 952190d..f2139ba 100644 --- a/src/Deferred.php +++ b/src/Deferred.php @@ -76,7 +76,7 @@ public function getState(): string /** * Resolve this deferred with a Response. - * + * * @param ResponseInterface $response */ public function resolve(ResponseInterface $response) @@ -95,7 +95,7 @@ public function resolve(ResponseInterface $response) /** * Reject this deferred with an Exception. - * + * * @param Exception $exception */ public function reject(Exception $exception) diff --git a/src/FlexibleHttpClient.php b/src/FlexibleHttpClient.php index e731f8c..58f8813 100644 --- a/src/FlexibleHttpClient.php +++ b/src/FlexibleHttpClient.php @@ -4,7 +4,6 @@ use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; -use Psr\Http\Client\ClientInterface; /** * A flexible http client, which implements both interface and will emulate diff --git a/src/HttpAsyncClientDecorator.php b/src/HttpAsyncClientDecorator.php index 3e82c75..6eb576c 100644 --- a/src/HttpAsyncClientDecorator.php +++ b/src/HttpAsyncClientDecorator.php @@ -3,7 +3,6 @@ namespace Http\Client\Common; use Http\Client\HttpAsyncClient; -use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** From 236a8ea112db5e05c2e5244f875bbdb1e4f27ce0 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 20 Nov 2018 14:39:56 +0100 Subject: [PATCH 03/14] Add spec to autoload-dev --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index fc3d1c1..7ada728 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,11 @@ "Http\\Client\\Common\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "spec\\Http\\Client\\Common\\": "spec/" + } + }, "scripts": { "test": "vendor/bin/phpspec run", "test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml" From 2a807054aa989509a695c2f30f91988d5eaa4910 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 20 Nov 2018 14:42:23 +0100 Subject: [PATCH 04/14] Fix signatures --- spec/HttpMethodsClientSpec.php | 2 +- src/HttpClientPool/RoundRobinClientPool.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/HttpMethodsClientSpec.php b/spec/HttpMethodsClientSpec.php index 07c0b47..28f2718 100644 --- a/spec/HttpMethodsClientSpec.php +++ b/spec/HttpMethodsClientSpec.php @@ -100,7 +100,7 @@ class HttpMethodsClientStub extends HttpMethodsClient /** * {@inheritdoc} */ - public function send($method, $uri, array $headers = [], $body = null) + public function send($method, $uri, array $headers = [], $body = null): ResponseInterface { if (in_array($method, ['GET', 'HEAD', 'TRACE'])) { return $uri === self::$requestData['uri'] && diff --git a/src/HttpClientPool/RoundRobinClientPool.php b/src/HttpClientPool/RoundRobinClientPool.php index fe33c37..3315b51 100644 --- a/src/HttpClientPool/RoundRobinClientPool.php +++ b/src/HttpClientPool/RoundRobinClientPool.php @@ -4,6 +4,7 @@ use Http\Client\Common\Exception\HttpClientNotFoundException; use Http\Client\Common\HttpClientPool; +use Http\Client\Common\HttpClientPoolItem; /** * RoundRobinClientPool will choose the next client in the pool. From e87785c00e5c1b246d8416cee23522f62b7e695c Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 20 Nov 2018 15:37:54 +0100 Subject: [PATCH 05/14] Use ::class anywhere --- spec/BatchClientSpec.php | 12 ++++-- spec/BatchResultSpec.php | 7 ++-- spec/EmulatedHttpAsyncClientSpec.php | 17 +++++--- spec/EmulatedHttpClientSpec.php | 10 +++-- spec/Exception/BatchExceptionSpec.php | 9 ++-- spec/FlexibleHttpClientSpec.php | 15 +++---- .../LeastUsedClientPoolSpec.php | 25 ++++++----- spec/HttpClientPool/RandomClientPoolSpec.php | 25 ++++++----- .../RoundRobinClientPoolSpec.php | 25 ++++++----- spec/HttpClientPoolItemSpec.php | 15 +++---- spec/HttpClientRouterSpec.php | 12 +++--- spec/HttpMethodsClientSpec.php | 3 +- spec/Plugin/AddHostPluginSpec.php | 6 ++- spec/Plugin/AddPathPluginSpec.php | 10 +++-- spec/Plugin/AuthenticationPluginSpec.php | 6 ++- spec/Plugin/BaseUriPluginSpec.php | 6 ++- spec/Plugin/ContentLengthPluginSpec.php | 6 ++- spec/Plugin/ContentTypePluginSpec.php | 6 ++- spec/Plugin/CookiePluginSpec.php | 16 +++++--- spec/Plugin/DecoderPluginSpec.php | 12 ++++-- spec/Plugin/ErrorPluginSpec.php | 21 ++++++---- spec/Plugin/HeaderAppendPluginSpec.php | 6 ++- spec/Plugin/HeaderDefaultsPluginSpec.php | 6 ++- spec/Plugin/HeaderRemovePluginSpec.php | 6 ++- spec/Plugin/HeaderSetPluginSpec.php | 6 ++- spec/Plugin/HistoryPluginSpec.php | 3 +- spec/Plugin/QueryDefaultsPluginSpec.php | 5 ++- spec/Plugin/RedirectPluginSpec.php | 41 +++++++++++-------- spec/Plugin/RequestMatcherPluginSpec.php | 5 ++- spec/Plugin/RetryPluginSpec.php | 16 ++++---- spec/PluginClientFactorySpec.php | 6 ++- spec/PluginClientSpec.php | 14 ++++--- 32 files changed, 226 insertions(+), 152 deletions(-) diff --git a/spec/BatchClientSpec.php b/spec/BatchClientSpec.php index 962f00a..2120605 100644 --- a/spec/BatchClientSpec.php +++ b/spec/BatchClientSpec.php @@ -6,12 +6,16 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\BatchClient; +use Http\Client\Common\BatchResult; +use Http\Client\Exception\HttpException; +use Http\Client\Common\Exception\BatchException; class BatchClientSpec extends ObjectBehavior { function let(HttpClient $client) { - $this->beAnInstanceOf('Http\Client\Common\BatchClient', [$client]); + $this->beAnInstanceOf(BatchClient::class, [$client]); } function it_send_multiple_request_using_send_request(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response1, ResponseInterface $response2) @@ -19,14 +23,14 @@ function it_send_multiple_request_using_send_request(HttpClient $client, Request $client->sendRequest($request1)->willReturn($response1); $client->sendRequest($request2)->willReturn($response2); - $this->sendRequests([$request1, $request2])->shouldReturnAnInstanceOf('Http\Client\Common\BatchResult'); + $this->sendRequests([$request1, $request2])->shouldReturnAnInstanceOf(BatchResult::class); } function it_throw_batch_exception_if_one_or_more_request_failed(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response) { $client->sendRequest($request1)->willReturn($response); - $client->sendRequest($request2)->willThrow('Http\Client\Exception\HttpException'); + $client->sendRequest($request2)->willThrow(HttpException::class); - $this->shouldThrow('Http\Client\Common\Exception\BatchException')->duringSendRequests([$request1, $request2]); + $this->shouldThrow(BatchException::class)->duringSendRequests([$request1, $request2]); } } diff --git a/spec/BatchResultSpec.php b/spec/BatchResultSpec.php index c4618ac..702ac11 100644 --- a/spec/BatchResultSpec.php +++ b/spec/BatchResultSpec.php @@ -6,12 +6,13 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\BatchResult; class BatchResultSpec extends ObjectBehavior { function it_is_initializable() { - $this->beAnInstanceOf('Http\Client\Common\BatchResult'); + $this->beAnInstanceOf(BatchResult::class); } function it_is_immutable(RequestInterface $request, ResponseInterface $response) @@ -19,7 +20,7 @@ function it_is_immutable(RequestInterface $request, ResponseInterface $response) $new = $this->addResponse($request, $response); $this->getResponses()->shouldReturn([]); - $new->shouldHaveType('Http\Client\Common\BatchResult'); + $new->shouldHaveType(BatchResult::class); $new->getResponses()->shouldReturn([$response]); } @@ -37,7 +38,7 @@ function it_has_a_response_for_a_request(RequestInterface $request, ResponseInte { $new = $this->addResponse($request, $response); - $this->shouldThrow('UnexpectedValueException')->duringGetResponseFor($request); + $this->shouldThrow(\UnexpectedValueException::class)->duringGetResponseFor($request); $this->isSuccessful($request)->shouldReturn(false); $new->getResponseFor($request)->shouldReturn($response); $new->isSuccessful($request)->shouldReturn(true); diff --git a/spec/EmulatedHttpAsyncClientSpec.php b/spec/EmulatedHttpAsyncClientSpec.php index b7a9edd..d122fff 100644 --- a/spec/EmulatedHttpAsyncClientSpec.php +++ b/spec/EmulatedHttpAsyncClientSpec.php @@ -6,6 +6,11 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\EmulatedHttpAsyncClient; +use Http\Client\HttpAsyncClient; +use Http\Client\Promise\HttpFulfilledPromise; +use Http\Client\Exception\TransferException; +use Http\Client\Promise\HttpRejectedPromise; class EmulatedHttpAsyncClientSpec extends ObjectBehavior { @@ -16,17 +21,17 @@ function let(HttpClient $httpClient) function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\EmulatedHttpAsyncClient'); + $this->shouldHaveType(EmulatedHttpAsyncClient::class); } function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } function it_is_an_async_http_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } function it_emulates_a_successful_request( @@ -36,14 +41,14 @@ function it_emulates_a_successful_request( ) { $httpClient->sendRequest($request)->willReturn($response); - $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); + $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); } function it_emulates_a_failed_request(HttpClient $httpClient, RequestInterface $request) { - $httpClient->sendRequest($request)->willThrow('Http\Client\Exception\TransferException'); + $httpClient->sendRequest($request)->willThrow(TransferException::class); - $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); + $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf(HttpRejectedPromise::class); } function it_decorates_the_underlying_client( diff --git a/spec/EmulatedHttpClientSpec.php b/spec/EmulatedHttpClientSpec.php index 976f772..6a39f64 100644 --- a/spec/EmulatedHttpClientSpec.php +++ b/spec/EmulatedHttpClientSpec.php @@ -9,6 +9,8 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\EmulatedHttpClient; +use Http\Client\Exception; class EmulatedHttpClientSpec extends ObjectBehavior { @@ -19,17 +21,17 @@ function let(HttpAsyncClient $httpAsyncClient) function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\EmulatedHttpClient'); + $this->shouldHaveType(EmulatedHttpClient::class); } function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } function it_is_an_async_http_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } function it_emulates_a_successful_request( @@ -55,7 +57,7 @@ function it_emulates_a_failed_request(HttpAsyncClient $httpAsyncClient, RequestI $httpAsyncClient->sendAsyncRequest($request)->willReturn($promise); - $this->shouldThrow('Http\Client\Exception')->duringSendRequest($request); + $this->shouldThrow(Exception::class)->duringSendRequest($request); } function it_decorates_the_underlying_client( diff --git a/spec/Exception/BatchExceptionSpec.php b/spec/Exception/BatchExceptionSpec.php index fa8d8d6..5a852a7 100644 --- a/spec/Exception/BatchExceptionSpec.php +++ b/spec/Exception/BatchExceptionSpec.php @@ -5,6 +5,7 @@ use Http\Client\Common\BatchResult; use Http\Client\Exception; use PhpSpec\ObjectBehavior; +use Http\Client\Common\Exception\BatchException; class BatchExceptionSpec extends ObjectBehavior { @@ -16,21 +17,21 @@ function let() function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Exception\BatchException'); + $this->shouldHaveType(BatchException::class); } function it_is_a_runtime_exception() { - $this->shouldHaveType('RuntimeException'); + $this->shouldHaveType(\RuntimeException::class); } function it_is_an_exception() { - $this->shouldImplement('Http\Client\Exception'); + $this->shouldImplement(Exception::class); } function it_has_a_batch_result() { - $this->getResult()->shouldHaveType('Http\Client\Common\BatchResult'); + $this->getResult()->shouldHaveType(BatchResult::class); } } diff --git a/spec/FlexibleHttpClientSpec.php b/spec/FlexibleHttpClientSpec.php index 70e6e4d..c1ff256 100644 --- a/spec/FlexibleHttpClientSpec.php +++ b/spec/FlexibleHttpClientSpec.php @@ -8,6 +8,7 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\FlexibleHttpClient; class FlexibleHttpClientSpec extends ObjectBehavior { @@ -18,24 +19,24 @@ function let(HttpClient $httpClient) function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\FlexibleHttpClient'); + $this->shouldHaveType(FlexibleHttpClient::class); } function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } function it_is_an_async_http_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } function it_throw_exception_if_invalid_client() { $this->beConstructedWith(null); - $this->shouldThrow('\LogicException')->duringInstantiation(); + $this->shouldThrow(\LogicException::class)->duringInstantiation(); } function it_emulates_an_async_client( @@ -53,7 +54,7 @@ function it_emulates_an_async_client( $this->sendRequest($syncRequest)->shouldReturn($syncResponse); $promise = $this->sendAsyncRequest($asyncRequest); - $promise->shouldHaveType('Http\Promise\Promise'); + $promise->shouldHaveType(Promise::class); $promise->wait()->shouldReturn($asyncResponse); } @@ -77,8 +78,8 @@ function it_emulates_a_client( function it_does_not_emulate_a_client($client, RequestInterface $syncRequest, RequestInterface $asyncRequest) { - $client->implement('Http\Client\HttpClient'); - $client->implement('Http\Client\HttpAsyncClient'); + $client->implement(HttpClient::class); + $client->implement(HttpAsyncClient::class); $client->sendRequest($syncRequest)->shouldBeCalled(); $client->sendRequest($asyncRequest)->shouldNotBeCalled(); diff --git a/spec/HttpClientPool/LeastUsedClientPoolSpec.php b/spec/HttpClientPool/LeastUsedClientPoolSpec.php index 82855d9..6a4aeda 100644 --- a/spec/HttpClientPool/LeastUsedClientPoolSpec.php +++ b/spec/HttpClientPool/LeastUsedClientPoolSpec.php @@ -11,28 +11,31 @@ use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Http\Client\Common\HttpClientPool\LeastUsedClientPool; +use Http\Client\Common\Exception\HttpClientNotFoundException; +use Http\Client\Exception\HttpException; class LeastUsedClientPoolSpec extends ObjectBehavior { public function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\HttpClientPool\LeastUsedClientPool'); + $this->shouldHaveType(LeastUsedClientPool::class); } public function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } public function it_is_an_async_http_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } public function it_throw_exception_with_no_client(RequestInterface $request) { - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendAsyncRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendAsyncRequest($request); } public function it_sends_request(HttpClient $httpClient, RequestInterface $request, ResponseInterface $response) @@ -55,19 +58,19 @@ public function it_sends_async_request(HttpAsyncClient $httpAsyncClient, Request public function it_throw_exception_if_no_more_enable_client(HttpClient $client, RequestInterface $request) { $this->addHttpClient($client); - $client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException'); + $client->sendRequest($request)->willThrow(HttpException::class); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request); } public function it_reenable_client(HttpClient $client, RequestInterface $request) { $this->addHttpClient(new HttpClientPoolItem($client->getWrappedObject(), 0)); - $client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException'); + $client->sendRequest($request)->willThrow(HttpException::class); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); } public function it_uses_the_lowest_request_client(HttpClientPoolItem $client1, HttpClientPoolItem $client2, RequestInterface $request, ResponseInterface $response) diff --git a/spec/HttpClientPool/RandomClientPoolSpec.php b/spec/HttpClientPool/RandomClientPoolSpec.php index 4054d82..fb0e5ad 100644 --- a/spec/HttpClientPool/RandomClientPoolSpec.php +++ b/spec/HttpClientPool/RandomClientPoolSpec.php @@ -10,28 +10,31 @@ use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Http\Client\Common\HttpClientPool\RandomClientPool; +use Http\Client\Common\Exception\HttpClientNotFoundException; +use Http\Client\Exception\HttpException; class RandomClientPoolSpec extends ObjectBehavior { public function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\HttpClientPool\RandomClientPool'); + $this->shouldHaveType(RandomClientPool::class); } public function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } public function it_is_an_async_http_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } public function it_throw_exception_with_no_client(RequestInterface $request) { - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendAsyncRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendAsyncRequest($request); } public function it_sends_request(HttpClient $httpClient, RequestInterface $request, ResponseInterface $response) @@ -54,18 +57,18 @@ public function it_sends_async_request(HttpAsyncClient $httpAsyncClient, Request public function it_throw_exception_if_no_more_enable_client(HttpClient $client, RequestInterface $request) { $this->addHttpClient($client); - $client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException'); + $client->sendRequest($request)->willThrow(HttpException::class); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request); } public function it_reenable_client(HttpClient $client, RequestInterface $request) { $this->addHttpClient(new HttpClientPoolItem($client->getWrappedObject(), 0)); - $client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException'); + $client->sendRequest($request)->willThrow(HttpException::class); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); } } diff --git a/spec/HttpClientPool/RoundRobinClientPoolSpec.php b/spec/HttpClientPool/RoundRobinClientPoolSpec.php index 48c2d01..925f548 100644 --- a/spec/HttpClientPool/RoundRobinClientPoolSpec.php +++ b/spec/HttpClientPool/RoundRobinClientPoolSpec.php @@ -10,28 +10,31 @@ use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Http\Client\Common\HttpClientPool\RoundRobinClientPool; +use Http\Client\Common\Exception\HttpClientNotFoundException; +use Http\Client\Exception\HttpException; class RoundRobinClientPoolSpec extends ObjectBehavior { public function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\HttpClientPool\RoundRobinClientPool'); + $this->shouldHaveType(RoundRobinClientPool::class); } public function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } public function it_is_an_async_http_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } public function it_throw_exception_with_no_client(RequestInterface $request) { - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendAsyncRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendAsyncRequest($request); } public function it_sends_request(HttpClient $httpClient, RequestInterface $request, ResponseInterface $response) @@ -54,19 +57,19 @@ public function it_sends_async_request(HttpAsyncClient $httpAsyncClient, Request public function it_throw_exception_if_no_more_enable_client(HttpClient $client, RequestInterface $request) { $this->addHttpClient($client); - $client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException'); + $client->sendRequest($request)->willThrow(HttpException::class); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); + $this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request); } public function it_reenable_client(HttpClient $client, RequestInterface $request) { $this->addHttpClient(new HttpClientPoolItem($client->getWrappedObject(), 0)); - $client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException'); + $client->sendRequest($request)->willThrow(HttpException::class); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); - $this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); + $this->shouldThrow(HttpException::class)->duringSendRequest($request); } public function it_round_between_clients(HttpClient $client1, HttpClient $client2, RequestInterface $request, ResponseInterface $response) diff --git a/spec/HttpClientPoolItemSpec.php b/spec/HttpClientPoolItemSpec.php index 059ec8d..09935ad 100644 --- a/spec/HttpClientPoolItemSpec.php +++ b/spec/HttpClientPoolItemSpec.php @@ -12,6 +12,7 @@ use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Http\Client\Exception\RequestException; class HttpClientPoolItemSpec extends ObjectBehavior { @@ -22,12 +23,12 @@ public function let(HttpClient $httpClient) public function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } public function it_is_an_async_http_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } public function it_sends_request(HttpClient $httpClient, RequestInterface $request, ResponseInterface $response) @@ -53,7 +54,7 @@ public function it_disable_himself_on_send_request(HttpClient $httpClient, Reque $httpClient->sendRequest($request)->willThrow($exception); $this->shouldThrow($exception)->duringSendRequest($request); $this->isDisabled()->shouldReturn(true); - $this->shouldThrow('Http\Client\Exception\RequestException')->duringSendRequest($request); + $this->shouldThrow(RequestException::class)->duringSendRequest($request); } public function it_disable_himself_on_send_async_request(HttpAsyncClient $httpAsyncClient, RequestInterface $request) @@ -63,9 +64,9 @@ public function it_disable_himself_on_send_async_request(HttpAsyncClient $httpAs $promise = new HttpRejectedPromise(new TransferException()); $httpAsyncClient->sendAsyncRequest($request)->willReturn($promise); - $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); + $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf(HttpRejectedPromise::class); $this->isDisabled()->shouldReturn(true); - $this->shouldThrow('Http\Client\Exception\RequestException')->duringSendAsyncRequest($request); + $this->shouldThrow(RequestException::class)->duringSendAsyncRequest($request); } public function it_reactivate_himself_on_send_request(HttpClient $httpClient, RequestInterface $request) @@ -87,9 +88,9 @@ public function it_reactivate_himself_on_send_async_request(HttpAsyncClient $htt $promise = new HttpRejectedPromise(new TransferException()); $httpAsyncClient->sendAsyncRequest($request)->willReturn($promise); - $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); + $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf(HttpRejectedPromise::class); $this->isDisabled()->shouldReturn(false); - $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); + $this->sendAsyncRequest($request)->shouldReturnAnInstanceOf(HttpRejectedPromise::class); } public function it_increments_request_count(HttpAsyncClient $httpAsyncClient, RequestInterface $request, ResponseInterface $response) diff --git a/spec/HttpClientRouterSpec.php b/spec/HttpClientRouterSpec.php index 1119722..5b88308 100644 --- a/spec/HttpClientRouterSpec.php +++ b/spec/HttpClientRouterSpec.php @@ -9,22 +9,24 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\HttpClientRouter; +use Http\Client\Exception\RequestException; class HttpClientRouterSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\HttpClientRouter'); + $this->shouldHaveType(HttpClientRouter::class); } function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } function it_is_an_async_http_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } function it_send_request(RequestMatcher $matcher, HttpClient $client, RequestInterface $request, ResponseInterface $response) @@ -50,7 +52,7 @@ function it_throw_exception_on_send_request(RequestMatcher $matcher, HttpClient $this->addClient($client, $matcher); $matcher->matches($request)->willReturn(false); - $this->shouldThrow('Http\Client\Exception\RequestException')->duringSendRequest($request); + $this->shouldThrow(RequestException::class)->duringSendRequest($request); } function it_throw_exception_on_send_async_request(RequestMatcher $matcher, HttpAsyncClient $client, RequestInterface $request) @@ -58,6 +60,6 @@ function it_throw_exception_on_send_async_request(RequestMatcher $matcher, HttpA $this->addClient($client, $matcher); $matcher->matches($request)->willReturn(false); - $this->shouldThrow('Http\Client\Exception\RequestException')->duringSendAsyncRequest($request); + $this->shouldThrow(RequestException::class)->duringSendAsyncRequest($request); } } diff --git a/spec/HttpMethodsClientSpec.php b/spec/HttpMethodsClientSpec.php index 28f2718..5ba9d2f 100644 --- a/spec/HttpMethodsClientSpec.php +++ b/spec/HttpMethodsClientSpec.php @@ -2,7 +2,6 @@ namespace spec\Http\Client\Common; -use Http\Client\BatchResult; use Http\Client\HttpClient; use Http\Client\Common\HttpMethodsClient; use Http\Message\MessageFactory; @@ -15,7 +14,7 @@ class HttpMethodsClientSpec extends ObjectBehavior function let(HttpClient $client, MessageFactory $messageFactory) { $this->beAnInstanceOf( - 'spec\Http\Client\Common\HttpMethodsClientStub', [ + HttpMethodsClientStub::class, [ $client, $messageFactory ] diff --git a/spec/Plugin/AddHostPluginSpec.php b/spec/Plugin/AddHostPluginSpec.php index caf4f21..6c59bed 100644 --- a/spec/Plugin/AddHostPluginSpec.php +++ b/spec/Plugin/AddHostPluginSpec.php @@ -7,6 +7,8 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\Plugin\AddHostPlugin; +use Http\Client\Common\Plugin; class AddHostPluginSpec extends ObjectBehavior { @@ -19,14 +21,14 @@ function it_is_initializable(UriInterface $uri) { $uri->getHost()->shouldBeCalled()->willReturn('example.com'); - $this->shouldHaveType('Http\Client\Common\Plugin\AddHostPlugin'); + $this->shouldHaveType(AddHostPlugin::class); } function it_is_a_plugin(UriInterface $uri) { $uri->getHost()->shouldBeCalled()->willReturn('example.com'); - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_adds_domain( diff --git a/spec/Plugin/AddPathPluginSpec.php b/spec/Plugin/AddPathPluginSpec.php index a7ec9b5..da65d4f 100644 --- a/spec/Plugin/AddPathPluginSpec.php +++ b/spec/Plugin/AddPathPluginSpec.php @@ -7,6 +7,8 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\Plugin\AddPathPlugin; +use Http\Client\Common\Plugin; class AddPathPluginSpec extends ObjectBehavior { @@ -19,14 +21,14 @@ function it_is_initializable(UriInterface $uri) { $uri->getPath()->shouldBeCalled()->willReturn('/api'); - $this->shouldHaveType('Http\Client\Common\Plugin\AddPathPlugin'); + $this->shouldHaveType(AddPathPlugin::class); } function it_is_a_plugin(UriInterface $uri) { $uri->getPath()->shouldBeCalled()->willReturn('/api'); - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_adds_path( @@ -51,7 +53,7 @@ function it_throws_exception_on_trailing_slash(UriInterface $host) $host->getPath()->shouldBeCalled()->willReturn('/api/'); $this->beConstructedWith($host); - $this->shouldThrow('\LogicException')->duringInstantiation(); + $this->shouldThrow(\LogicException::class)->duringInstantiation(); } function it_throws_exception_on_empty_path(UriInterface $host) @@ -59,6 +61,6 @@ function it_throws_exception_on_empty_path(UriInterface $host) $host->getPath()->shouldBeCalled()->willReturn(''); $this->beConstructedWith($host); - $this->shouldThrow('\LogicException')->duringInstantiation(); + $this->shouldThrow(\LogicException::class)->duringInstantiation(); } } diff --git a/spec/Plugin/AuthenticationPluginSpec.php b/spec/Plugin/AuthenticationPluginSpec.php index 02d1187..9d98c05 100644 --- a/spec/Plugin/AuthenticationPluginSpec.php +++ b/spec/Plugin/AuthenticationPluginSpec.php @@ -7,6 +7,8 @@ use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\AuthenticationPlugin; +use Http\Client\Common\Plugin; class AuthenticationPluginSpec extends ObjectBehavior { @@ -17,12 +19,12 @@ function let(Authentication $authentication) function it_is_initializable(Authentication $authentication) { - $this->shouldHaveType('Http\Client\Common\Plugin\AuthenticationPlugin'); + $this->shouldHaveType(AuthenticationPlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_sends_an_authenticated_request(Authentication $authentication, RequestInterface $notAuthedRequest, RequestInterface $authedRequest, Promise $promise) diff --git a/spec/Plugin/BaseUriPluginSpec.php b/spec/Plugin/BaseUriPluginSpec.php index 2faf769..06b6990 100644 --- a/spec/Plugin/BaseUriPluginSpec.php +++ b/spec/Plugin/BaseUriPluginSpec.php @@ -7,6 +7,8 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\Plugin\BaseUriPlugin; +use Http\Client\Common\Plugin; class BaseUriPluginSpec extends ObjectBehavior { @@ -20,7 +22,7 @@ function it_is_initializable(UriInterface $uri) $uri->getHost()->shouldBeCalled()->willReturn('example.com'); $uri->getPath()->shouldBeCalled()->willReturn('/api'); - $this->shouldHaveType('Http\Client\Common\Plugin\BaseUriPlugin'); + $this->shouldHaveType(BaseUriPlugin::class); } function it_is_a_plugin(UriInterface $uri) @@ -28,7 +30,7 @@ function it_is_a_plugin(UriInterface $uri) $uri->getHost()->shouldBeCalled()->willReturn('example.com'); $uri->getPath()->shouldBeCalled()->willReturn('/api'); - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_adds_domain_and_path( diff --git a/spec/Plugin/ContentLengthPluginSpec.php b/spec/Plugin/ContentLengthPluginSpec.php index 4ec2ba7..96a9b66 100644 --- a/spec/Plugin/ContentLengthPluginSpec.php +++ b/spec/Plugin/ContentLengthPluginSpec.php @@ -7,17 +7,19 @@ use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\ContentLengthPlugin; +use Http\Client\Common\Plugin; class ContentLengthPluginSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Plugin\ContentLengthPlugin'); + $this->shouldHaveType(ContentLengthPlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_adds_content_length_header(RequestInterface $request, StreamInterface $stream) diff --git a/spec/Plugin/ContentTypePluginSpec.php b/spec/Plugin/ContentTypePluginSpec.php index 3df7d87..5745086 100644 --- a/spec/Plugin/ContentTypePluginSpec.php +++ b/spec/Plugin/ContentTypePluginSpec.php @@ -7,17 +7,19 @@ use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\ContentTypePlugin; +use Http\Client\Common\Plugin; class ContentTypePluginSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Plugin\ContentTypePlugin'); + $this->shouldHaveType(ContentTypePlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_adds_json_content_type_header(RequestInterface $request) diff --git a/spec/Plugin/CookiePluginSpec.php b/spec/Plugin/CookiePluginSpec.php index 2bb47e7..039df63 100644 --- a/spec/Plugin/CookiePluginSpec.php +++ b/spec/Plugin/CookiePluginSpec.php @@ -11,6 +11,10 @@ use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\CookiePlugin; +use Http\Client\Common\Plugin; +use Http\Client\Promise\HttpRejectedPromise; +use Http\Client\Exception\TransferException; class CookiePluginSpec extends ObjectBehavior { @@ -25,12 +29,12 @@ function let() function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Plugin\CookiePlugin'); + $this->shouldHaveType(CookiePlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_loads_cookie(RequestInterface $request, UriInterface $uri, Promise $promise) @@ -216,8 +220,8 @@ function it_saves_cookie(RequestInterface $request, ResponseInterface $response, $uri->getPath()->willReturn('/'); $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldHaveType('Http\Promise\Promise'); - $promise->wait()->shouldReturnAnInstanceOf('Psr\Http\Message\ResponseInterface'); + $promise->shouldHaveType(Promise::class); + $promise->wait()->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_throws_exception_on_invalid_expires_date( @@ -239,7 +243,7 @@ function it_throws_exception_on_invalid_expires_date( $uri->getPath()->willReturn('/'); $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); - $promise->shouldThrow('Http\Client\Exception\TransferException')->duringWait(); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); + $promise->shouldThrow(TransferException::class)->duringWait(); } } diff --git a/spec/Plugin/DecoderPluginSpec.php b/spec/Plugin/DecoderPluginSpec.php index 7543027..d098f48 100644 --- a/spec/Plugin/DecoderPluginSpec.php +++ b/spec/Plugin/DecoderPluginSpec.php @@ -9,17 +9,21 @@ use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\DecoderPlugin; +use Http\Client\Common\Plugin; +use Http\Message\Encoding\GzipDecodeStream; +use Http\Message\Encoding\DecompressStream; class DecoderPluginSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Plugin\DecoderPlugin'); + $this->shouldHaveType(DecoderPlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_decodes(RequestInterface $request, ResponseInterface $response, StreamInterface $stream) @@ -60,7 +64,7 @@ function it_decodes_gzip(RequestInterface $request, ResponseInterface $response, $response->hasHeader('Content-Encoding')->willReturn(true); $response->getHeader('Content-Encoding')->willReturn(['gzip']); $response->getBody()->willReturn($stream); - $response->withBody(Argument::type('Http\Message\Encoding\GzipDecodeStream'))->willReturn($response); + $response->withBody(Argument::type(GzipDecodeStream::class))->willReturn($response); $response->withoutHeader('Content-Encoding')->willReturn($response); $stream->isReadable()->willReturn(true); @@ -82,7 +86,7 @@ function it_decodes_deflate(RequestInterface $request, ResponseInterface $respon $response->hasHeader('Content-Encoding')->willReturn(true); $response->getHeader('Content-Encoding')->willReturn(['deflate']); $response->getBody()->willReturn($stream); - $response->withBody(Argument::type('Http\Message\Encoding\DecompressStream'))->willReturn($response); + $response->withBody(Argument::type(DecompressStream::class))->willReturn($response); $response->withoutHeader('Content-Encoding')->willReturn($response); $stream->isReadable()->willReturn(true); diff --git a/spec/Plugin/ErrorPluginSpec.php b/spec/Plugin/ErrorPluginSpec.php index 20fcc25..409dcf0 100644 --- a/spec/Plugin/ErrorPluginSpec.php +++ b/spec/Plugin/ErrorPluginSpec.php @@ -7,17 +7,22 @@ use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\ErrorPlugin; +use Http\Client\Common\Plugin; +use Http\Client\Promise\HttpRejectedPromise; +use Http\Client\Common\Exception\ClientErrorException; +use Http\Client\Common\Exception\ServerErrorException; class ErrorPluginSpec extends ObjectBehavior { function it_is_initializable() { - $this->beAnInstanceOf('Http\Client\Common\Plugin\ErrorPlugin'); + $this->beAnInstanceOf(ErrorPlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_throw_client_error_exception_on_4xx_error(RequestInterface $request, ResponseInterface $response) @@ -32,8 +37,8 @@ function it_throw_client_error_exception_on_4xx_error(RequestInterface $request, }; $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); - $promise->shouldThrow('Http\Client\Common\Exception\ClientErrorException')->duringWait(); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); + $promise->shouldThrow(ClientErrorException::class)->duringWait(); } function it_does_not_throw_client_error_exception_on_4xx_error_if_only_server_exception(RequestInterface $request, ResponseInterface $response) @@ -49,7 +54,7 @@ function it_does_not_throw_client_error_exception_on_4xx_error_if_only_server_ex } }; - $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); + $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); } function it_throw_server_error_exception_on_5xx_error(RequestInterface $request, ResponseInterface $response) @@ -64,8 +69,8 @@ function it_throw_server_error_exception_on_5xx_error(RequestInterface $request, }; $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); - $promise->shouldThrow('Http\Client\Common\Exception\ServerErrorException')->duringWait(); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); + $promise->shouldThrow(ServerErrorException::class)->duringWait(); } function it_returns_response(RequestInterface $request, ResponseInterface $response) @@ -78,6 +83,6 @@ function it_returns_response(RequestInterface $request, ResponseInterface $respo } }; - $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); + $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); } } diff --git a/spec/Plugin/HeaderAppendPluginSpec.php b/spec/Plugin/HeaderAppendPluginSpec.php index 24b8565..229ef55 100644 --- a/spec/Plugin/HeaderAppendPluginSpec.php +++ b/spec/Plugin/HeaderAppendPluginSpec.php @@ -7,19 +7,21 @@ use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\HeaderAppendPlugin; +use Http\Client\Common\Plugin; class HeaderAppendPluginSpec extends ObjectBehavior { public function it_is_initializable() { $this->beConstructedWith([]); - $this->shouldHaveType('Http\Client\Common\Plugin\HeaderAppendPlugin'); + $this->shouldHaveType(HeaderAppendPlugin::class); } public function it_is_a_plugin() { $this->beConstructedWith([]); - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } public function it_appends_the_header(RequestInterface $request) diff --git a/spec/Plugin/HeaderDefaultsPluginSpec.php b/spec/Plugin/HeaderDefaultsPluginSpec.php index 341f1a5..ca6aeda 100644 --- a/spec/Plugin/HeaderDefaultsPluginSpec.php +++ b/spec/Plugin/HeaderDefaultsPluginSpec.php @@ -7,19 +7,21 @@ use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\HeaderDefaultsPlugin; +use Http\Client\Common\Plugin; class HeaderDefaultsPluginSpec extends ObjectBehavior { public function it_is_initializable() { $this->beConstructedWith([]); - $this->shouldHaveType('Http\Client\Common\Plugin\HeaderDefaultsPlugin'); + $this->shouldHaveType(HeaderDefaultsPlugin::class); } public function it_is_a_plugin() { $this->beConstructedWith([]); - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } public function it_sets_the_default_header(RequestInterface $request) diff --git a/spec/Plugin/HeaderRemovePluginSpec.php b/spec/Plugin/HeaderRemovePluginSpec.php index 9ea2752..4fd1b6a 100644 --- a/spec/Plugin/HeaderRemovePluginSpec.php +++ b/spec/Plugin/HeaderRemovePluginSpec.php @@ -7,19 +7,21 @@ use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\HeaderRemovePlugin; +use Http\Client\Common\Plugin; class HeaderRemovePluginSpec extends ObjectBehavior { public function it_is_initializable() { $this->beConstructedWith([]); - $this->shouldHaveType('Http\Client\Common\Plugin\HeaderRemovePlugin'); + $this->shouldHaveType(HeaderRemovePlugin::class); } public function it_is_a_plugin() { $this->beConstructedWith([]); - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } public function it_removes_the_header(RequestInterface $request) diff --git a/spec/Plugin/HeaderSetPluginSpec.php b/spec/Plugin/HeaderSetPluginSpec.php index f4a340c..4cd0bf4 100644 --- a/spec/Plugin/HeaderSetPluginSpec.php +++ b/spec/Plugin/HeaderSetPluginSpec.php @@ -7,19 +7,21 @@ use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\HeaderSetPlugin; +use Http\Client\Common\Plugin; class HeaderSetPluginSpec extends ObjectBehavior { public function it_is_initializable() { $this->beConstructedWith([]); - $this->shouldHaveType('Http\Client\Common\Plugin\HeaderSetPlugin'); + $this->shouldHaveType(HeaderSetPlugin::class); } public function it_is_a_plugin() { $this->beConstructedWith([]); - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } public function it_set_the_header(RequestInterface $request) diff --git a/spec/Plugin/HistoryPluginSpec.php b/spec/Plugin/HistoryPluginSpec.php index 24e7f51..cb2bfb0 100644 --- a/spec/Plugin/HistoryPluginSpec.php +++ b/spec/Plugin/HistoryPluginSpec.php @@ -10,6 +10,7 @@ use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin; class HistoryPluginSpec extends ObjectBehavior { @@ -25,7 +26,7 @@ function it_is_initializable() function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_records_success(Journal $journal, RequestInterface $request, ResponseInterface $response) diff --git a/spec/Plugin/QueryDefaultsPluginSpec.php b/spec/Plugin/QueryDefaultsPluginSpec.php index 82d9125..1af5133 100644 --- a/spec/Plugin/QueryDefaultsPluginSpec.php +++ b/spec/Plugin/QueryDefaultsPluginSpec.php @@ -6,6 +6,7 @@ use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; use Psr\Http\Message\UriInterface; +use Http\Client\Common\Plugin\QueryDefaultsPlugin; class QueryDefaultsPluginSpec extends ObjectBehavior { @@ -16,12 +17,12 @@ public function let() public function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Plugin\QueryDefaultsPlugin'); + $this->shouldHaveType(QueryDefaultsPlugin::class); } public function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } public function it_sets_the_default_header(RequestInterface $request, UriInterface $uri) diff --git a/spec/Plugin/RedirectPluginSpec.php b/spec/Plugin/RedirectPluginSpec.php index 97197e1..459d2e5 100644 --- a/spec/Plugin/RedirectPluginSpec.php +++ b/spec/Plugin/RedirectPluginSpec.php @@ -10,17 +10,24 @@ use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin; +use spec\Http\Client\Common\Plugin\RedirectPluginStub; +use Http\Client\Promise\HttpRejectedPromise; +use Http\Client\Exception\HttpException; +use Http\Client\Common\Exception\MultipleRedirectionException; +use spec\Http\Client\Common\Plugin\RedirectPluginStubCircular; +use Http\Client\Common\Exception\CircularRedirectionException; class RedirectPluginSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Plugin\RedirectPlugin'); + $this->shouldHaveType(RedirectPlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_redirects_on_302( @@ -65,13 +72,13 @@ function it_redirects_on_302( $promise->wait()->shouldBeCalled()->willReturn($finalResponse); $finalPromise = $this->handleRequest($request, $next, $first); - $finalPromise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); + $finalPromise->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); $finalPromise->wait()->shouldReturn($finalResponse); } function it_use_storage_on_301(UriInterface $uri, UriInterface $uriRedirect, RequestInterface $request, RequestInterface $modifiedRequest) { - $this->beAnInstanceOf('spec\Http\Client\Common\Plugin\RedirectPluginStub'); + $this->beAnInstanceOf(RedirectPluginStub::class); $this->beConstructedWith($uriRedirect, '/original', '301'); $next = function () { @@ -100,7 +107,7 @@ function it_stores_a_301( Promise $promise ) { - $this->beAnInstanceOf('spec\Http\Client\Common\Plugin\RedirectPluginStub'); + $this->beAnInstanceOf(RedirectPluginStub::class); $this->beConstructedWith($uriRedirect, '', '301'); $request->getUri()->willReturn($uri); @@ -203,8 +210,8 @@ function it_throws_http_exception_on_no_location(RequestInterface $request, UriI $responseRedirect->hasHeader('Location')->willReturn(false); $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); - $promise->shouldThrow('Http\Client\Exception\HttpException')->duringWait(); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); + $promise->shouldThrow(HttpException::class)->duringWait(); } function it_throws_http_exception_on_invalid_location(RequestInterface $request, UriInterface $uri, ResponseInterface $responseRedirect) @@ -223,8 +230,8 @@ function it_throws_http_exception_on_invalid_location(RequestInterface $request, $responseRedirect->hasHeader('Location')->willReturn(true); $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); - $promise->shouldThrow('Http\Client\Exception\HttpException')->duringWait(); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); + $promise->shouldThrow(HttpException::class)->duringWait(); } function it_throw_multi_redirect_exception_on_300(RequestInterface $request, ResponseInterface $responseRedirect) @@ -239,8 +246,8 @@ function it_throw_multi_redirect_exception_on_300(RequestInterface $request, Res $responseRedirect->getStatusCode()->willReturn('300'); $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); - $promise->shouldThrow('Http\Client\Common\Exception\MultipleRedirectionException')->duringWait(); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); + $promise->shouldThrow(MultipleRedirectionException::class)->duringWait(); } function it_throw_multi_redirect_exception_on_300_if_no_location(RequestInterface $request, ResponseInterface $responseRedirect) @@ -255,8 +262,8 @@ function it_throw_multi_redirect_exception_on_300_if_no_location(RequestInterfac $responseRedirect->hasHeader('Location')->willReturn(false); $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); - $promise->shouldThrow('Http\Client\Common\Exception\MultipleRedirectionException')->duringWait(); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); + $promise->shouldThrow(MultipleRedirectionException::class)->duringWait(); } function it_switch_method_for_302( @@ -360,7 +367,7 @@ function it_throws_circular_redirection_exception(UriInterface $uri, UriInterfac { $first = function() {}; - $this->beAnInstanceOf('spec\Http\Client\Common\Plugin\RedirectPluginStubCircular'); + $this->beAnInstanceOf(RedirectPluginStubCircular::class); $this->beConstructedWith(spl_object_hash((object)$first)); $request->getUri()->willReturn($uri); @@ -386,8 +393,8 @@ function it_throws_circular_redirection_exception(UriInterface $uri, UriInterfac }; $promise = $this->handleRequest($request, $next, $first); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); - $promise->shouldThrow('Http\Client\Common\Exception\CircularRedirectionException')->duringWait(); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); + $promise->shouldThrow(CircularRedirectionException::class)->duringWait(); } function it_redirects_http_to_https( @@ -433,7 +440,7 @@ function it_redirects_http_to_https( $promise->wait()->shouldBeCalled()->willReturn($finalResponse); $finalPromise = $this->handleRequest($request, $next, $first); - $finalPromise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); + $finalPromise->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); $finalPromise->wait()->shouldReturn($finalResponse); } } diff --git a/spec/Plugin/RequestMatcherPluginSpec.php b/spec/Plugin/RequestMatcherPluginSpec.php index 4fe9aea..d5335b4 100644 --- a/spec/Plugin/RequestMatcherPluginSpec.php +++ b/spec/Plugin/RequestMatcherPluginSpec.php @@ -8,6 +8,7 @@ use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\RequestMatcherPlugin; class RequestMatcherPluginSpec extends ObjectBehavior { @@ -18,12 +19,12 @@ function let(RequestMatcher $requestMatcher, Plugin $plugin) function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Plugin\RequestMatcherPlugin'); + $this->shouldHaveType(RequestMatcherPlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_matches_a_request_and_delegates_to_plugin( diff --git a/spec/Plugin/RetryPluginSpec.php b/spec/Plugin/RetryPluginSpec.php index 37800ae..080f4b3 100644 --- a/spec/Plugin/RetryPluginSpec.php +++ b/spec/Plugin/RetryPluginSpec.php @@ -9,17 +9,19 @@ use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Http\Client\Common\Plugin\RetryPlugin; +use Http\Client\Common\Plugin; class RetryPluginSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\Plugin\RetryPlugin'); + $this->shouldHaveType(RetryPlugin::class); } function it_is_a_plugin() { - $this->shouldImplement('Http\Client\Common\Plugin'); + $this->shouldImplement(Plugin::class); } function it_returns_response(RequestInterface $request, ResponseInterface $response) @@ -30,7 +32,7 @@ function it_returns_response(RequestInterface $request, ResponseInterface $respo } }; - $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); + $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); } function it_throws_exception_on_multiple_exceptions(RequestInterface $request) @@ -53,7 +55,7 @@ function it_throws_exception_on_multiple_exceptions(RequestInterface $request) }; $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise'); + $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class); $promise->shouldThrow($exception2)->duringWait(); } @@ -76,7 +78,7 @@ function it_returns_response_on_second_try(RequestInterface $request, ResponseIn }; $promise = $this->handleRequest($request, $next, function () {}); - $promise->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); + $promise->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); $promise->wait()->shouldReturn($response); } @@ -98,8 +100,8 @@ function it_does_not_keep_history_of_old_failure(RequestInterface $request, Resp } }; - $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); - $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise'); + $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); + $this->handleRequest($request, $next, function () {})->shouldReturnAnInstanceOf(HttpFulfilledPromise::class); } function it_has_an_exponential_default_delay(RequestInterface $request, Exception\HttpException $exception) diff --git a/spec/PluginClientFactorySpec.php b/spec/PluginClientFactorySpec.php index 1f8d9e8..173c7ec 100644 --- a/spec/PluginClientFactorySpec.php +++ b/spec/PluginClientFactorySpec.php @@ -4,19 +4,21 @@ use Http\Client\HttpClient; use PhpSpec\ObjectBehavior; +use Http\Client\Common\PluginClientFactory; +use Http\Client\Common\PluginClient; class PluginClientFactorySpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\PluginClientFactory'); + $this->shouldHaveType(PluginClientFactory::class); } function it_returns_a_plugin_client(HttpClient $httpClient) { $client = $this->createClient($httpClient); - $client->shouldHaveType('Http\Client\Common\PluginClient'); + $client->shouldHaveType(PluginClient::class); } function it_does_not_construct_plugin_client_with_client_name_option(HttpClient $httpClient) diff --git a/spec/PluginClientSpec.php b/spec/PluginClientSpec.php index addb2e8..687d8e0 100644 --- a/spec/PluginClientSpec.php +++ b/spec/PluginClientSpec.php @@ -11,6 +11,8 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; +use Http\Client\Common\Exception\LoopException; +use Http\Client\Common\PluginClient; class PluginClientSpec extends ObjectBehavior { @@ -21,17 +23,17 @@ function let(HttpClient $httpClient) function it_is_initializable() { - $this->shouldHaveType('Http\Client\Common\PluginClient'); + $this->shouldHaveType(PluginClient::class); } function it_is_an_http_client() { - $this->shouldImplement('Http\Client\HttpClient'); + $this->shouldImplement(HttpClient::class); } function it_is_an_http_async_client() { - $this->shouldImplement('Http\Client\HttpAsyncClient'); + $this->shouldImplement(HttpAsyncClient::class); } function it_sends_request_with_underlying_client(HttpClient $httpClient, RequestInterface $request, ResponseInterface $response) @@ -60,8 +62,8 @@ function it_sends_async_request_if_no_send_request(HttpAsyncClient $httpAsyncCli function it_prefers_send_request($client, RequestInterface $request, ResponseInterface $response) { - $client->implement('Http\Client\HttpClient'); - $client->implement('Http\Client\HttpAsyncClient'); + $client->implement(HttpClient::class); + $client->implement(HttpAsyncClient::class); $client->sendRequest($request)->willReturn($response); @@ -85,7 +87,7 @@ function it_throws_loop_exception(HttpClient $httpClient, RequestInterface $requ $this->beConstructedWith($httpClient, [$plugin]); - $this->shouldThrow('Http\Client\Common\Exception\LoopException')->duringSendRequest($request); + $this->shouldThrow(LoopException::class)->duringSendRequest($request); } function it_injects_debug_plugins(HttpClient $httpClient, ResponseInterface $response, RequestInterface $request, Plugin $plugin0, Plugin $plugin1, Plugin $debugPlugin) From 68c6f7a8161ad38d4d8d4bd38fc1a36ea0e75baf Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 20 Nov 2018 16:07:26 +0100 Subject: [PATCH 06/14] Fix HttpMethodsClientSpec --- spec/HttpMethodsClientSpec.php | 53 ++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/spec/HttpMethodsClientSpec.php b/spec/HttpMethodsClientSpec.php index 5ba9d2f..08f8a2f 100644 --- a/spec/HttpMethodsClientSpec.php +++ b/spec/HttpMethodsClientSpec.php @@ -2,6 +2,7 @@ namespace spec\Http\Client\Common; +use GuzzleHttp\Psr7\Response; use Http\Client\HttpClient; use Http\Client\Common\HttpMethodsClient; use Http\Message\MessageFactory; @@ -25,56 +26,56 @@ function it_sends_a_get_request() { $data = HttpMethodsClientStub::$requestData; - $this->get($data['uri'], $data['headers'])->shouldReturn(true); + $this->get($data['uri'], $data['headers'])->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_sends_a_head_request() { $data = HttpMethodsClientStub::$requestData; - $this->head($data['uri'], $data['headers'])->shouldReturn(true); + $this->head($data['uri'], $data['headers'])->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_sends_a_trace_request() { $data = HttpMethodsClientStub::$requestData; - $this->trace($data['uri'], $data['headers'])->shouldReturn(true); + $this->trace($data['uri'], $data['headers'])->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_sends_a_post_request() { $data = HttpMethodsClientStub::$requestData; - $this->post($data['uri'], $data['headers'], $data['body'])->shouldReturn(true); + $this->post($data['uri'], $data['headers'], $data['body'])->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_sends_a_put_request() { $data = HttpMethodsClientStub::$requestData; - $this->put($data['uri'], $data['headers'], $data['body'])->shouldReturn(true); + $this->put($data['uri'], $data['headers'], $data['body'])->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_sends_a_patch_request() { $data = HttpMethodsClientStub::$requestData; - $this->patch($data['uri'], $data['headers'], $data['body'])->shouldReturn(true); + $this->patch($data['uri'], $data['headers'], $data['body'])->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_sends_a_delete_request() { $data = HttpMethodsClientStub::$requestData; - $this->delete($data['uri'], $data['headers'], $data['body'])->shouldReturn(true); + $this->delete($data['uri'], $data['headers'], $data['body'])->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_sends_a_options_request() { $data = HttpMethodsClientStub::$requestData; - $this->options($data['uri'], $data['headers'], $data['body'])->shouldReturn(true); + $this->options($data['uri'], $data['headers'], $data['body'])->shouldReturnAnInstanceOf(ResponseInterface::class); } function it_sends_request_with_underlying_client(HttpClient $client, MessageFactory $messageFactory, RequestInterface $request, ResponseInterface $response) @@ -101,15 +102,35 @@ class HttpMethodsClientStub extends HttpMethodsClient */ public function send($method, $uri, array $headers = [], $body = null): ResponseInterface { - if (in_array($method, ['GET', 'HEAD', 'TRACE'])) { - return $uri === self::$requestData['uri'] && - $headers === self::$requestData['headers'] && - is_null($body); + if ($uri !== self::$requestData['uri']) { + throw new \InvalidArgumentException('Invalid URI: ' . $uri); } - return in_array($method, ['POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']) && - $uri === self::$requestData['uri'] && - $headers === self::$requestData['headers'] && - $body === self::$requestData['body']; + if ($headers !== self::$requestData['headers']) { + throw new \InvalidArgumentException('Invalid headers: ' . print_r($headers, true)); + } + + switch ($method) { + case 'GET': + case 'HEAD': + case 'TRACE': + if ($body !== null) { + throw new \InvalidArgumentException('Non-empty body'); + } + + return new Response(); + case 'POST': + case 'PUT': + case 'PATCH': + case 'DELETE': + case 'OPTIONS': + if ($body !== self::$requestData['body']) { + throw new \InvalidArgumentException('Invalid body: ' . print_r($body, true)); + } + + return new Response(); + default: + throw new \InvalidArgumentException('Invalid method: ' . $method); + } } } From e963de568cd1a7a1a0016083fbf05b5a26e00c50 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 20 Nov 2018 17:46:30 +0100 Subject: [PATCH 07/14] Reapply CS --- spec/HttpMethodsClientSpec.php | 10 +++++----- src/BatchResult.php | 10 ---------- src/Deferred.php | 4 ---- src/HttpMethodsClient.php | 18 ------------------ src/Plugin/ContentTypePlugin.php | 2 -- src/Plugin/RedirectPlugin.php | 2 -- src/PluginClient.php | 4 ---- src/PluginClientFactory.php | 2 -- 8 files changed, 5 insertions(+), 47 deletions(-) diff --git a/spec/HttpMethodsClientSpec.php b/spec/HttpMethodsClientSpec.php index 28551d7..74e0810 100644 --- a/spec/HttpMethodsClientSpec.php +++ b/spec/HttpMethodsClientSpec.php @@ -103,18 +103,18 @@ class HttpMethodsClientStub extends HttpMethodsClient public function send($method, $uri, array $headers = [], $body = null): ResponseInterface { if ($uri !== self::$requestData['uri']) { - throw new \InvalidArgumentException('Invalid URI: ' . $uri); + throw new \InvalidArgumentException('Invalid URI: '.$uri); } if ($headers !== self::$requestData['headers']) { - throw new \InvalidArgumentException('Invalid headers: ' . print_r($headers, true)); + throw new \InvalidArgumentException('Invalid headers: '.print_r($headers, true)); } switch ($method) { case 'GET': case 'HEAD': case 'TRACE': - if ($body !== null) { + if (null !== $body) { throw new \InvalidArgumentException('Non-empty body'); } @@ -125,12 +125,12 @@ public function send($method, $uri, array $headers = [], $body = null): Response case 'DELETE': case 'OPTIONS': if ($body !== self::$requestData['body']) { - throw new \InvalidArgumentException('Invalid body: ' . print_r($body, true)); + throw new \InvalidArgumentException('Invalid body: '.print_r($body, true)); } return new Response(); default: - throw new \InvalidArgumentException('Invalid method: ' . $method); + throw new \InvalidArgumentException('Invalid method: '.$method); } } } diff --git a/src/BatchResult.php b/src/BatchResult.php index 320b64b..94ff51a 100644 --- a/src/BatchResult.php +++ b/src/BatchResult.php @@ -31,8 +31,6 @@ public function __construct() /** * Checks if there are any successful responses at all. - * - * @return bool */ public function hasResponses(): bool { @@ -57,8 +55,6 @@ public function getResponses(): array /** * Checks if there is a successful response for a request. - * - * @return bool */ public function isSuccessful(RequestInterface $request): bool { @@ -68,7 +64,6 @@ public function isSuccessful(RequestInterface $request): bool /** * Returns the response for a successful request. * - * @return ResponseInterface * * @throws \UnexpectedValueException If request was not part of the batch or failed */ @@ -96,8 +91,6 @@ public function addResponse(RequestInterface $request, ResponseInterface $respon /** * Checks if there are any unsuccessful requests at all. - * - * @return bool */ public function hasExceptions(): bool { @@ -122,8 +115,6 @@ public function getExceptions(): array /** * Checks if there is an exception for a request, meaning the request failed. - * - * @return bool */ public function isFailed(RequestInterface $request): bool { @@ -133,7 +124,6 @@ public function isFailed(RequestInterface $request): bool /** * Returns the exception for a failed request. * - * @return Exception * * @throws \UnexpectedValueException If request was not part of the batch or was successful */ diff --git a/src/Deferred.php b/src/Deferred.php index f2139ba..7413451 100644 --- a/src/Deferred.php +++ b/src/Deferred.php @@ -76,8 +76,6 @@ public function getState(): string /** * Resolve this deferred with a Response. - * - * @param ResponseInterface $response */ public function resolve(ResponseInterface $response) { @@ -95,8 +93,6 @@ public function resolve(ResponseInterface $response) /** * Reject this deferred with an Exception. - * - * @param Exception $exception */ public function reject(Exception $exception) { diff --git a/src/HttpMethodsClient.php b/src/HttpMethodsClient.php index b6f281c..bc02ef8 100644 --- a/src/HttpMethodsClient.php +++ b/src/HttpMethodsClient.php @@ -52,8 +52,6 @@ public function __construct(HttpClient $httpClient, RequestFactory $requestFacto * @param string|UriInterface $uri * * @throws Exception - * - * @return ResponseInterface */ public function get($uri, array $headers = []): ResponseInterface { @@ -66,8 +64,6 @@ public function get($uri, array $headers = []): ResponseInterface * @param string|UriInterface $uri * * @throws Exception - * - * @return ResponseInterface */ public function head($uri, array $headers = []): ResponseInterface { @@ -80,8 +76,6 @@ public function head($uri, array $headers = []): ResponseInterface * @param string|UriInterface $uri * * @throws Exception - * - * @return ResponseInterface */ public function trace($uri, array $headers = []): ResponseInterface { @@ -95,8 +89,6 @@ public function trace($uri, array $headers = []): ResponseInterface * @param string|StreamInterface|null $body * * @throws Exception - * - * @return ResponseInterface */ public function post($uri, array $headers = [], $body = null): ResponseInterface { @@ -110,8 +102,6 @@ public function post($uri, array $headers = [], $body = null): ResponseInterface * @param string|StreamInterface|null $body * * @throws Exception - * - * @return ResponseInterface */ public function put($uri, array $headers = [], $body = null): ResponseInterface { @@ -125,8 +115,6 @@ public function put($uri, array $headers = [], $body = null): ResponseInterface * @param string|StreamInterface|null $body * * @throws Exception - * - * @return ResponseInterface */ public function patch($uri, array $headers = [], $body = null): ResponseInterface { @@ -140,8 +128,6 @@ public function patch($uri, array $headers = [], $body = null): ResponseInterfac * @param string|StreamInterface|null $body * * @throws Exception - * - * @return ResponseInterface */ public function delete($uri, array $headers = [], $body = null): ResponseInterface { @@ -155,8 +141,6 @@ public function delete($uri, array $headers = [], $body = null): ResponseInterfa * @param string|StreamInterface|null $body * * @throws Exception - * - * @return ResponseInterface */ public function options($uri, array $headers = [], $body = null): ResponseInterface { @@ -171,8 +155,6 @@ public function options($uri, array $headers = [], $body = null): ResponseInterf * @param string|StreamInterface|null $body * * @throws Exception - * - * @return ResponseInterface */ public function send($method, $uri, array $headers = [], $body = null): ResponseInterface { diff --git a/src/Plugin/ContentTypePlugin.php b/src/Plugin/ContentTypePlugin.php index cdeba9a..b056648 100644 --- a/src/Plugin/ContentTypePlugin.php +++ b/src/Plugin/ContentTypePlugin.php @@ -93,8 +93,6 @@ public function handleRequest(RequestInterface $request, callable $next, callabl /** * @param $stream StreamInterface - * - * @return bool */ private function isJson($stream): bool { diff --git a/src/Plugin/RedirectPlugin.php b/src/Plugin/RedirectPlugin.php index dce9995..598968b 100644 --- a/src/Plugin/RedirectPlugin.php +++ b/src/Plugin/RedirectPlugin.php @@ -215,8 +215,6 @@ protected function buildRedirectRequest(RequestInterface $request, UriInterface * * @throws HttpException If location header is not usable (missing or incorrect) * @throws MultipleRedirectionException If a 300 status code is received and default location cannot be resolved (doesn't use the location header or not present) - * - * @return UriInterface */ private function createUri(ResponseInterface $response, RequestInterface $request): UriInterface { diff --git a/src/PluginClient.php b/src/PluginClient.php index 3ec0c92..264c2fe 100644 --- a/src/PluginClient.php +++ b/src/PluginClient.php @@ -101,8 +101,6 @@ public function sendAsyncRequest(RequestInterface $request) /** * Configure the plugin client. - * - * @return array */ private function configure(array $options = []): array { @@ -121,8 +119,6 @@ private function configure(array $options = []): array * * @param Plugin[] $pluginList A list of plugins * @param callable $clientCallable Callable making the HTTP call - * - * @return callable */ private function createPluginChain(array $pluginList, callable $clientCallable): callable { diff --git a/src/PluginClientFactory.php b/src/PluginClientFactory.php index 0509adf..77642ea 100644 --- a/src/PluginClientFactory.php +++ b/src/PluginClientFactory.php @@ -42,8 +42,6 @@ public static function setFactory(callable $factory) * } * * @see PluginClient constructor for PluginClient specific $options. - * - * @return PluginClient */ public function createClient($client, array $plugins = [], array $options = []): PluginClient { From 14aacb7bd1d6d19f70352f525c57eed28861cd59 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 20 Nov 2018 17:55:44 +0100 Subject: [PATCH 08/14] Fix a few imports lost in the merge --- spec/EmulatedHttpClientSpec.php | 1 + spec/Exception/BatchExceptionSpec.php | 1 + spec/Plugin/QueryDefaultsPluginSpec.php | 1 + 3 files changed, 3 insertions(+) diff --git a/spec/EmulatedHttpClientSpec.php b/spec/EmulatedHttpClientSpec.php index 7dd5bfc..adf206f 100644 --- a/spec/EmulatedHttpClientSpec.php +++ b/spec/EmulatedHttpClientSpec.php @@ -4,6 +4,7 @@ use Http\Client\Exception\TransferException; use Http\Client\HttpAsyncClient; +use Http\Client\HttpClient; use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; diff --git a/spec/Exception/BatchExceptionSpec.php b/spec/Exception/BatchExceptionSpec.php index 953e974..0205843 100644 --- a/spec/Exception/BatchExceptionSpec.php +++ b/spec/Exception/BatchExceptionSpec.php @@ -3,6 +3,7 @@ namespace spec\Http\Client\Common\Exception; use Http\Client\Common\BatchResult; +use Http\Client\Exception; use PhpSpec\ObjectBehavior; use Http\Client\Common\Exception\BatchException; diff --git a/spec/Plugin/QueryDefaultsPluginSpec.php b/spec/Plugin/QueryDefaultsPluginSpec.php index 7cf61d0..1af5133 100644 --- a/spec/Plugin/QueryDefaultsPluginSpec.php +++ b/spec/Plugin/QueryDefaultsPluginSpec.php @@ -2,6 +2,7 @@ namespace spec\Http\Client\Common\Plugin; +use Http\Client\Common\Plugin; use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; use Psr\Http\Message\UriInterface; From ce05e535d53090733bca62bd131c9f18004f8b85 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Nov 2018 10:12:40 +0100 Subject: [PATCH 09/14] Add `: Promise` return type to Plugin::handleRequest --- src/Plugin.php | 5 +++-- src/Plugin/AddHostPlugin.php | 3 ++- src/Plugin/AddPathPlugin.php | 3 ++- src/Plugin/AuthenticationPlugin.php | 3 ++- src/Plugin/BaseUriPlugin.php | 3 ++- src/Plugin/ContentLengthPlugin.php | 3 ++- src/Plugin/ContentTypePlugin.php | 3 ++- src/Plugin/CookiePlugin.php | 3 ++- src/Plugin/DecoderPlugin.php | 3 ++- src/Plugin/ErrorPlugin.php | 3 ++- src/Plugin/HeaderAppendPlugin.php | 3 ++- src/Plugin/HeaderDefaultsPlugin.php | 3 ++- src/Plugin/HeaderRemovePlugin.php | 3 ++- src/Plugin/HeaderSetPlugin.php | 3 ++- src/Plugin/HistoryPlugin.php | 3 ++- src/Plugin/QueryDefaultsPlugin.php | 3 ++- src/Plugin/RedirectPlugin.php | 3 ++- src/Plugin/RequestMatcherPlugin.php | 3 ++- src/Plugin/RetryPlugin.php | 3 ++- 19 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index bfb2668..3890c29 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -22,10 +22,11 @@ interface Plugin * * @see http://docs.php-http.org/en/latest/plugins/build-your-own.html * - * @param callable $next Next middleware in the chain, the request is passed as the first argument + * @param RequestInterface $request + * @param callable $next Next middleware in the chain, the request is passed as the first argument * @param callable $first First middleware in the chain, used to to restart a request * * @return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception (The same as HttpAsyncClient) */ - public function handleRequest(RequestInterface $request, callable $next, callable $first); + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise; } diff --git a/src/Plugin/AddHostPlugin.php b/src/Plugin/AddHostPlugin.php index 050feb1..492667e 100644 --- a/src/Plugin/AddHostPlugin.php +++ b/src/Plugin/AddHostPlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -48,7 +49,7 @@ public function __construct(UriInterface $host, array $config = []) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { if ($this->replace || '' === $request->getUri()->getHost()) { $uri = $request->getUri() diff --git a/src/Plugin/AddPathPlugin.php b/src/Plugin/AddPathPlugin.php index 1675088..ae5d97d 100644 --- a/src/Plugin/AddPathPlugin.php +++ b/src/Plugin/AddPathPlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; @@ -41,7 +42,7 @@ public function __construct(UriInterface $uri) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $identifier = spl_object_hash((object) $first); diff --git a/src/Plugin/AuthenticationPlugin.php b/src/Plugin/AuthenticationPlugin.php index ff33f9b..5b6c447 100644 --- a/src/Plugin/AuthenticationPlugin.php +++ b/src/Plugin/AuthenticationPlugin.php @@ -4,6 +4,7 @@ use Http\Client\Common\Plugin; use Http\Message\Authentication; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -26,7 +27,7 @@ public function __construct(Authentication $authentication) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $request = $this->authentication->authenticate($request); diff --git a/src/Plugin/BaseUriPlugin.php b/src/Plugin/BaseUriPlugin.php index 669c308..ee9e075 100644 --- a/src/Plugin/BaseUriPlugin.php +++ b/src/Plugin/BaseUriPlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; @@ -39,7 +40,7 @@ public function __construct(UriInterface $uri, array $hostConfig = []) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $addHostNext = function (RequestInterface $request) use ($next, $first) { return $this->addHostPlugin->handleRequest($request, $next, $first); diff --git a/src/Plugin/ContentLengthPlugin.php b/src/Plugin/ContentLengthPlugin.php index 0f7aafa..dff2ca8 100644 --- a/src/Plugin/ContentLengthPlugin.php +++ b/src/Plugin/ContentLengthPlugin.php @@ -4,6 +4,7 @@ use Http\Client\Common\Plugin; use Http\Message\Encoding\ChunkStream; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -16,7 +17,7 @@ final class ContentLengthPlugin implements Plugin /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { if (!$request->hasHeader('Content-Length')) { $stream = $request->getBody(); diff --git a/src/Plugin/ContentTypePlugin.php b/src/Plugin/ContentTypePlugin.php index b056648..190f125 100644 --- a/src/Plugin/ContentTypePlugin.php +++ b/src/Plugin/ContentTypePlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -57,7 +58,7 @@ public function __construct(array $config = []) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { if (!$request->hasHeader('Content-Type')) { $stream = $request->getBody(); diff --git a/src/Plugin/CookiePlugin.php b/src/Plugin/CookiePlugin.php index ac845a8..84669cf 100644 --- a/src/Plugin/CookiePlugin.php +++ b/src/Plugin/CookiePlugin.php @@ -8,6 +8,7 @@ use Http\Message\CookieJar; use Http\Message\CookieUtil; use Http\Message\Exception\UnexpectedValueException; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -33,7 +34,7 @@ public function __construct(CookieJar $cookieJar) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $cookies = []; foreach ($this->cookieJar->getCookies() as $cookie) { diff --git a/src/Plugin/DecoderPlugin.php b/src/Plugin/DecoderPlugin.php index 3a28f5b..0930779 100644 --- a/src/Plugin/DecoderPlugin.php +++ b/src/Plugin/DecoderPlugin.php @@ -4,6 +4,7 @@ use Http\Client\Common\Plugin; use Http\Message\Encoding; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -48,7 +49,7 @@ public function __construct(array $config = []) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $encodings = extension_loaded('zlib') ? ['gzip', 'deflate'] : ['identity']; diff --git a/src/Plugin/ErrorPlugin.php b/src/Plugin/ErrorPlugin.php index 3932121..1d25fb7 100644 --- a/src/Plugin/ErrorPlugin.php +++ b/src/Plugin/ErrorPlugin.php @@ -5,6 +5,7 @@ use Http\Client\Common\Exception\ClientErrorException; use Http\Client\Common\Exception\ServerErrorException; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -46,7 +47,7 @@ public function __construct(array $config = []) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $promise = $next($request); diff --git a/src/Plugin/HeaderAppendPlugin.php b/src/Plugin/HeaderAppendPlugin.php index 86f9a1d..ca44836 100644 --- a/src/Plugin/HeaderAppendPlugin.php +++ b/src/Plugin/HeaderAppendPlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -34,7 +35,7 @@ public function __construct(array $headers) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { foreach ($this->headers as $header => $headerValue) { $request = $request->withAddedHeader($header, $headerValue); diff --git a/src/Plugin/HeaderDefaultsPlugin.php b/src/Plugin/HeaderDefaultsPlugin.php index 6dfc111..77ffe8c 100644 --- a/src/Plugin/HeaderDefaultsPlugin.php +++ b/src/Plugin/HeaderDefaultsPlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -30,7 +31,7 @@ public function __construct(array $headers) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { foreach ($this->headers as $header => $headerValue) { if (!$request->hasHeader($header)) { diff --git a/src/Plugin/HeaderRemovePlugin.php b/src/Plugin/HeaderRemovePlugin.php index fc9c19d..0a34248 100644 --- a/src/Plugin/HeaderRemovePlugin.php +++ b/src/Plugin/HeaderRemovePlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -28,7 +29,7 @@ public function __construct(array $headers) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { foreach ($this->headers as $header) { if ($request->hasHeader($header)) { diff --git a/src/Plugin/HeaderSetPlugin.php b/src/Plugin/HeaderSetPlugin.php index f9723f0..210bb42 100644 --- a/src/Plugin/HeaderSetPlugin.php +++ b/src/Plugin/HeaderSetPlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -30,7 +31,7 @@ public function __construct(array $headers) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { foreach ($this->headers as $header => $headerValue) { $request = $request->withHeader($header, $headerValue); diff --git a/src/Plugin/HistoryPlugin.php b/src/Plugin/HistoryPlugin.php index 0c59a2a..7b14485 100644 --- a/src/Plugin/HistoryPlugin.php +++ b/src/Plugin/HistoryPlugin.php @@ -4,6 +4,7 @@ use Http\Client\Common\Plugin; use Http\Client\Exception; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -29,7 +30,7 @@ public function __construct(Journal $journal) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $journal = $this->journal; diff --git a/src/Plugin/QueryDefaultsPlugin.php b/src/Plugin/QueryDefaultsPlugin.php index d9c06d6..2693507 100644 --- a/src/Plugin/QueryDefaultsPlugin.php +++ b/src/Plugin/QueryDefaultsPlugin.php @@ -3,6 +3,7 @@ namespace Http\Client\Common\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -31,7 +32,7 @@ public function __construct(array $queryParams) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $uri = $request->getUri(); diff --git a/src/Plugin/RedirectPlugin.php b/src/Plugin/RedirectPlugin.php index 598968b..80c5251 100644 --- a/src/Plugin/RedirectPlugin.php +++ b/src/Plugin/RedirectPlugin.php @@ -6,6 +6,7 @@ use Http\Client\Common\Exception\MultipleRedirectionException; use Http\Client\Common\Plugin; use Http\Client\Exception\HttpException; +use Http\Promise\Promise; use Psr\Http\Message\MessageInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -131,7 +132,7 @@ public function __construct(array $config = []) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { // Check in storage if (array_key_exists((string) $request->getUri(), $this->redirectStorage)) { diff --git a/src/Plugin/RequestMatcherPlugin.php b/src/Plugin/RequestMatcherPlugin.php index dd97b3c..d7d3f3d 100644 --- a/src/Plugin/RequestMatcherPlugin.php +++ b/src/Plugin/RequestMatcherPlugin.php @@ -4,6 +4,7 @@ use Http\Client\Common\Plugin; use Http\Message\RequestMatcher; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -32,7 +33,7 @@ public function __construct(RequestMatcher $requestMatcher, Plugin $delegatedPlu /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { if ($this->requestMatcher->matches($request)) { return $this->delegatedPlugin->handleRequest($request, $next, $first); diff --git a/src/Plugin/RetryPlugin.php b/src/Plugin/RetryPlugin.php index 96cfbb2..c10bce4 100644 --- a/src/Plugin/RetryPlugin.php +++ b/src/Plugin/RetryPlugin.php @@ -4,6 +4,7 @@ use Http\Client\Common\Plugin; use Http\Client\Exception; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -72,7 +73,7 @@ public function __construct(array $config = []) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $chainIdentifier = spl_object_hash((object) $first); From 0499a89fff296faf856285d3553d12822efe2e6a Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Nov 2018 11:38:34 +0100 Subject: [PATCH 10/14] Partially fix specs --- spec/Plugin/AddHostPluginSpec.php | 6 +++--- spec/Plugin/AddPathPluginSpec.php | 2 +- spec/Plugin/BaseUriPluginSpec.php | 6 +++--- spec/Plugin/ContentLengthPluginSpec.php | 4 ++-- spec/Plugin/ContentTypePluginSpec.php | 16 +++++++------- spec/Plugin/HeaderAppendPluginSpec.php | 2 +- spec/Plugin/HeaderDefaultsPluginSpec.php | 2 +- spec/Plugin/HeaderRemovePluginSpec.php | 2 +- spec/Plugin/HeaderSetPluginSpec.php | 2 +- spec/Plugin/PluginStub.php | 27 ++++++++++++++++++++++++ spec/Plugin/QueryDefaultsPluginSpec.php | 8 ++----- spec/Plugin/RedirectPluginSpec.php | 2 +- spec/Plugin/RequestMatcherPluginSpec.php | 2 +- 13 files changed, 52 insertions(+), 29 deletions(-) create mode 100644 spec/Plugin/PluginStub.php diff --git a/spec/Plugin/AddHostPluginSpec.php b/spec/Plugin/AddHostPluginSpec.php index b666c2e..2691f10 100644 --- a/spec/Plugin/AddHostPluginSpec.php +++ b/spec/Plugin/AddHostPluginSpec.php @@ -47,7 +47,7 @@ public function it_adds_domain( $uri->getHost()->shouldBeCalled()->willReturn(''); $this->beConstructedWith($host); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_replaces_domain( @@ -67,7 +67,7 @@ public function it_replaces_domain( $uri->withPort(8000)->shouldBeCalled()->willReturn($uri); $this->beConstructedWith($host, ['replace' => true]); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_nothing_when_domain_exists( @@ -79,6 +79,6 @@ public function it_does_nothing_when_domain_exists( $uri->getHost()->shouldBeCalled()->willReturn('default.com'); $this->beConstructedWith($host); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/AddPathPluginSpec.php b/spec/Plugin/AddPathPluginSpec.php index 089ed11..a76eb16 100644 --- a/spec/Plugin/AddPathPluginSpec.php +++ b/spec/Plugin/AddPathPluginSpec.php @@ -43,7 +43,7 @@ public function it_adds_path( $uri->getPath()->shouldBeCalled()->willReturn('/users'); $this->beConstructedWith($host); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_throws_exception_on_trailing_slash(UriInterface $host) diff --git a/spec/Plugin/BaseUriPluginSpec.php b/spec/Plugin/BaseUriPluginSpec.php index 76d8008..92f5074 100644 --- a/spec/Plugin/BaseUriPluginSpec.php +++ b/spec/Plugin/BaseUriPluginSpec.php @@ -52,7 +52,7 @@ public function it_adds_domain_and_path( $uri->getPath()->shouldBeCalled()->willReturn('/users'); $this->beConstructedWith($host); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_adds_domain( @@ -74,7 +74,7 @@ public function it_adds_domain( $uri->getHost()->shouldBeCalled()->willReturn(''); $this->beConstructedWith($host); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_replaces_domain_and_adds_path( @@ -97,6 +97,6 @@ public function it_replaces_domain_and_adds_path( $uri->getPath()->shouldBeCalled()->willReturn('/users'); $this->beConstructedWith($host, ['replace' => true]); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/ContentLengthPluginSpec.php b/spec/Plugin/ContentLengthPluginSpec.php index 0671407..a945924 100644 --- a/spec/Plugin/ContentLengthPluginSpec.php +++ b/spec/Plugin/ContentLengthPluginSpec.php @@ -29,7 +29,7 @@ public function it_adds_content_length_header(RequestInterface $request, StreamI $stream->getSize()->shouldBeCalled()->willReturn(100); $request->withHeader('Content-Length', '100')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_streams_chunked_if_no_size(RequestInterface $request, StreamInterface $stream) @@ -45,6 +45,6 @@ public function it_streams_chunked_if_no_size(RequestInterface $request, StreamI $request->withBody(Argument::type('Http\Message\Encoding\ChunkStream'))->shouldBeCalled()->willReturn($request); $request->withAddedHeader('Transfer-Encoding', 'chunked')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/ContentTypePluginSpec.php b/spec/Plugin/ContentTypePluginSpec.php index ff5fb8d..a27d32a 100644 --- a/spec/Plugin/ContentTypePluginSpec.php +++ b/spec/Plugin/ContentTypePluginSpec.php @@ -25,7 +25,7 @@ public function it_adds_json_content_type_header(RequestInterface $request) $request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for(json_encode(['foo' => 'bar']))); $request->withHeader('Content-Type', 'application/json')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_adds_xml_content_type_header(RequestInterface $request) @@ -34,7 +34,7 @@ public function it_adds_xml_content_type_header(RequestInterface $request) $request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('bar')); $request->withHeader('Content-Type', 'application/xml')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_set_content_type_header(RequestInterface $request) @@ -43,7 +43,7 @@ public function it_does_not_set_content_type_header(RequestInterface $request) $request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('foo')); $request->withHeader('Content-Type', null)->shouldNotBeCalled(); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_set_content_type_header_if_already_one(RequestInterface $request) @@ -52,7 +52,7 @@ public function it_does_not_set_content_type_header_if_already_one(RequestInterf $request->getBody()->shouldNotBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('foo')); $request->withHeader('Content-Type', null)->shouldNotBeCalled(); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_set_content_type_header_if_size_0_or_unknown(RequestInterface $request) @@ -61,7 +61,7 @@ public function it_does_not_set_content_type_header_if_size_0_or_unknown(Request $request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for()); $request->withHeader('Content-Type', null)->shouldNotBeCalled(); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_adds_xml_content_type_header_if_size_limit_is_not_reached_using_default_value(RequestInterface $request) @@ -74,7 +74,7 @@ public function it_adds_xml_content_type_header_if_size_limit_is_not_reached_usi $request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('bar')); $request->withHeader('Content-Type', 'application/xml')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_adds_xml_content_type_header_if_size_limit_is_not_reached(RequestInterface $request) @@ -88,7 +88,7 @@ public function it_adds_xml_content_type_header_if_size_limit_is_not_reached(Req $request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('bar')); $request->withHeader('Content-Type', 'application/xml')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_set_content_type_header_if_size_limit_is_reached(RequestInterface $request) @@ -102,6 +102,6 @@ public function it_does_not_set_content_type_header_if_size_limit_is_reached(Req $request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('bar')); $request->withHeader('Content-Type', null)->shouldNotBeCalled(); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/HeaderAppendPluginSpec.php b/spec/Plugin/HeaderAppendPluginSpec.php index 14ee3da..9325069 100644 --- a/spec/Plugin/HeaderAppendPluginSpec.php +++ b/spec/Plugin/HeaderAppendPluginSpec.php @@ -31,6 +31,6 @@ public function it_appends_the_header(RequestInterface $request) $request->withAddedHeader('foo', 'bar')->shouldBeCalled()->willReturn($request); $request->withAddedHeader('baz', 'qux')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/HeaderDefaultsPluginSpec.php b/spec/Plugin/HeaderDefaultsPluginSpec.php index 5ddc7b5..5a50a9c 100644 --- a/spec/Plugin/HeaderDefaultsPluginSpec.php +++ b/spec/Plugin/HeaderDefaultsPluginSpec.php @@ -32,6 +32,6 @@ public function it_sets_the_default_header(RequestInterface $request) $request->withHeader('foo', 'bar')->shouldBeCalled()->willReturn($request); $request->hasHeader('baz')->shouldBeCalled()->willReturn(true); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/HeaderRemovePluginSpec.php b/spec/Plugin/HeaderRemovePluginSpec.php index 11b4ef2..3f60359 100644 --- a/spec/Plugin/HeaderRemovePluginSpec.php +++ b/spec/Plugin/HeaderRemovePluginSpec.php @@ -33,6 +33,6 @@ public function it_removes_the_header(RequestInterface $request) $request->hasHeader('baz')->shouldBeCalled()->willReturn(true); $request->withoutHeader('baz')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/HeaderSetPluginSpec.php b/spec/Plugin/HeaderSetPluginSpec.php index 9f044f9..b152567 100644 --- a/spec/Plugin/HeaderSetPluginSpec.php +++ b/spec/Plugin/HeaderSetPluginSpec.php @@ -31,6 +31,6 @@ public function it_set_the_header(RequestInterface $request) $request->withHeader('foo', 'bar')->shouldBeCalled()->willReturn($request); $request->withHeader('baz', 'qux')->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/PluginStub.php b/spec/Plugin/PluginStub.php new file mode 100644 index 0000000..2f1f10f --- /dev/null +++ b/spec/Plugin/PluginStub.php @@ -0,0 +1,27 @@ +withQuery('test=true&foo=bar')->shouldBeCalled()->willReturn($uri); $request->withUri($uri)->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () { - }, function () { - }); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_replace_existing_request_value(RequestInterface $request, UriInterface $uri) @@ -53,8 +51,6 @@ public function it_does_not_replace_existing_request_value(RequestInterface $req $uri->withQuery('foo=new&bar=barDefault')->shouldBeCalled()->willReturn($uri); $request->withUri($uri)->shouldBeCalled()->willReturn($request); - $this->handleRequest($request, function () { - }, function () { - }); + $this->handleRequest($request, PluginStub::next(), function () {}); } } diff --git a/spec/Plugin/RedirectPluginSpec.php b/spec/Plugin/RedirectPluginSpec.php index 46a767e..e24b6b1 100644 --- a/spec/Plugin/RedirectPluginSpec.php +++ b/spec/Plugin/RedirectPluginSpec.php @@ -91,7 +91,7 @@ public function it_use_storage_on_301(UriInterface $uri, UriInterface $uriRedire $uriRedirect->__toString()->willReturn('/redirect'); - $this->handleRequest($request, $next, function () {}); + $this->handleRequest($request, $next, PluginStub::first()); } public function it_stores_a_301( diff --git a/spec/Plugin/RequestMatcherPluginSpec.php b/spec/Plugin/RequestMatcherPluginSpec.php index e7cc934..de7cae6 100644 --- a/spec/Plugin/RequestMatcherPluginSpec.php +++ b/spec/Plugin/RequestMatcherPluginSpec.php @@ -35,7 +35,7 @@ public function it_matches_a_request_and_delegates_to_plugin( $requestMatcher->matches($request)->willReturn(true); $plugin->handleRequest($request, Argument::type('callable'), Argument::type('callable'))->shouldBeCalled(); - $this->handleRequest($request, function () {}, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_match_a_request( From 2ee9b26d208d273af36ec11f273036d1e38ebd22 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Nov 2018 11:39:27 +0100 Subject: [PATCH 11/14] Fix CS --- spec/Plugin/PluginStub.php | 6 ++---- src/Plugin.php | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/spec/Plugin/PluginStub.php b/spec/Plugin/PluginStub.php index 2f1f10f..ead2a57 100644 --- a/spec/Plugin/PluginStub.php +++ b/spec/Plugin/PluginStub.php @@ -11,16 +11,14 @@ class PluginStub { public static function next(): callable { - return function (RequestInterface $request): Promise - { + return function (RequestInterface $request): Promise { return new FulfilledPromise(new Response()); }; } public static function first(): callable { - return function (RequestInterface $request): Promise - { + return function (RequestInterface $request): Promise { return new FulfilledPromise(new Response()); }; } diff --git a/src/Plugin.php b/src/Plugin.php index 3890c29..ab7e4a1 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -22,8 +22,7 @@ interface Plugin * * @see http://docs.php-http.org/en/latest/plugins/build-your-own.html * - * @param RequestInterface $request - * @param callable $next Next middleware in the chain, the request is passed as the first argument + * @param callable $next Next middleware in the chain, the request is passed as the first argument * @param callable $first First middleware in the chain, used to to restart a request * * @return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception (The same as HttpAsyncClient) From 418a32ce5974259e96bfa65c84eec8e8d3fd9fe1 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Nov 2018 12:31:25 +0100 Subject: [PATCH 12/14] Add info to changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c268e8..c6a01d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 2.0 (unreleased) +### Changed +- Abstract method `HttpClientPool::chooseHttpClient()` has now an explicit return type (`Http\Client\Common\HttpClientPoolItem`) +- Interface method `Plugin::handleRequest(...)` has now an explicit return type (`Http\Promise\Promise`) + ### Removed - Deprecated option `debug_plugins` has been removed from `PluginClient` From d245d74bb9e05a99685c99a919531937dfd8d6fb Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Nov 2018 15:24:35 +0100 Subject: [PATCH 13/14] Fix the CookiePlugin spec --- spec/Plugin/CookiePluginSpec.php | 54 ++++++-------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) diff --git a/spec/Plugin/CookiePluginSpec.php b/spec/Plugin/CookiePluginSpec.php index 7072a00..3bc05b0 100644 --- a/spec/Plugin/CookiePluginSpec.php +++ b/spec/Plugin/CookiePluginSpec.php @@ -48,11 +48,7 @@ public function it_loads_cookie(RequestInterface $request, UriInterface $uri, Pr $request->withAddedHeader('Cookie', 'name=value')->willReturn($request); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_combines_multiple_cookies_into_one_header(RequestInterface $request, UriInterface $uri, Promise $promise) @@ -69,11 +65,7 @@ public function it_combines_multiple_cookies_into_one_header(RequestInterface $r $request->withAddedHeader('Cookie', 'name=value; name2=value2')->willReturn($request); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_load_cookie_if_expired(RequestInterface $request, UriInterface $uri, Promise $promise) @@ -83,11 +75,7 @@ public function it_does_not_load_cookie_if_expired(RequestInterface $request, Ur $request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled(); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_load_cookie_if_domain_does_not_match(RequestInterface $request, UriInterface $uri, Promise $promise) @@ -100,11 +88,7 @@ public function it_does_not_load_cookie_if_domain_does_not_match(RequestInterfac $request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled(); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_load_cookie_on_hackish_domains(RequestInterface $request, UriInterface $uri, Promise $promise) @@ -122,11 +106,7 @@ public function it_does_not_load_cookie_on_hackish_domains(RequestInterface $req $request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled(); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } } @@ -141,11 +121,7 @@ public function it_loads_cookie_on_subdomains(RequestInterface $request, UriInte $request->withAddedHeader('Cookie', 'name=value')->willReturn($request); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_load_cookie_if_path_does_not_match(RequestInterface $request, UriInterface $uri, Promise $promise) @@ -159,11 +135,7 @@ public function it_does_not_load_cookie_if_path_does_not_match(RequestInterface $request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled(); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_does_not_load_cookie_when_cookie_is_secure(RequestInterface $request, UriInterface $uri, Promise $promise) @@ -178,11 +150,7 @@ public function it_does_not_load_cookie_when_cookie_is_secure(RequestInterface $ $request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled(); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_loads_cookie_when_cookie_is_secure(RequestInterface $request, UriInterface $uri, Promise $promise) @@ -197,11 +165,7 @@ public function it_loads_cookie_when_cookie_is_secure(RequestInterface $request, $request->withAddedHeader('Cookie', 'name=value')->willReturn($request); - $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) { - if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) { - return $promise->getWrappedObject(); - } - }, function () {}); + $this->handleRequest($request, PluginStub::next(), function () {}); } public function it_saves_cookie(RequestInterface $request, ResponseInterface $response, UriInterface $uri) From de025347778f1c1d4e5671d3d5d37048c7de0f30 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Nov 2018 15:25:01 +0100 Subject: [PATCH 14/14] Fix CS --- spec/Plugin/CookiePluginSpec.php | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/Plugin/CookiePluginSpec.php b/spec/Plugin/CookiePluginSpec.php index 3bc05b0..7bb188c 100644 --- a/spec/Plugin/CookiePluginSpec.php +++ b/spec/Plugin/CookiePluginSpec.php @@ -10,7 +10,6 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; use Http\Client\Common\Plugin\CookiePlugin; use Http\Client\Common\Plugin; use Http\Client\Promise\HttpRejectedPromise;