From 4956673e1a8d59203b08063895ca23cc2d86f8cf Mon Sep 17 00:00:00 2001 From: tzmfreedom Date: Sat, 9 Feb 2019 00:10:15 +0900 Subject: [PATCH] update httplug to 2.0 and related package --- .travis.yml | 2 -- composer.json | 8 ++++---- lib/Github/HttpClient/Plugin/Authentication.php | 3 ++- lib/Github/HttpClient/Plugin/GithubExceptionThrower.php | 3 ++- lib/Github/HttpClient/Plugin/History.php | 4 ++-- lib/Github/HttpClient/Plugin/PathPrepend.php | 3 ++- test/Github/Tests/Api/AbstractApiTest.php | 5 ++--- test/Github/Tests/HttpClient/PathPrependTest.php | 4 ++++ .../HttpClient/Plugin/GithubExceptionThrowerTest.php | 7 ++++--- 9 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a9b3776ba5..590e41db1d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ env: - TEST_COMMAND="vendor/bin/phpunit --verbose --coverage-text" php: - - 5.6 - - 7.0 - 7.1 - 7.2 - 7.3 diff --git a/composer.json b/composer.json index 4c1fcea4e9d..a69efc60464 100644 --- a/composer.json +++ b/composer.json @@ -17,18 +17,18 @@ } ], "require": { - "php": "^5.6 || ^7.0", + "php": "^7.1", "psr/http-message": "^1.0", "psr/cache": "^1.0", - "php-http/httplug": "^1.1", + "php-http/httplug": "^2.0", "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", - "php-http/client-common": "^1.6", + "php-http/client-common": "^2.0", "php-http/cache-plugin": "^1.4" }, "require-dev": { "phpunit/phpunit": "^5.5 || ^6.0", - "php-http/guzzle6-adapter": "^1.0", + "php-http/guzzle6-adapter": "^2.0", "php-http/mock-client": "^1.0", "guzzlehttp/psr7": "^1.2", "cache/array-adapter": "^0.4" diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 920d65722c6..03c954db371 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -5,6 +5,7 @@ use Github\Client; use Github\Exception\RuntimeException; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -28,7 +29,7 @@ public function __construct($tokenOrLogin, $password, $method) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { switch ($this->method) { case Client::AUTH_HTTP_PASSWORD: diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index a0593924b7a..9e49a251529 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -9,6 +9,7 @@ use Github\Exception\ValidationFailedException; use Github\HttpClient\Message\ResponseMediator; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -21,7 +22,7 @@ class GithubExceptionThrower implements Plugin /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { return $next($request)->then(function (ResponseInterface $response) use ($request) { if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) { diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index 303d81404dc..ab952c1e5a9 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -3,7 +3,7 @@ namespace Github\HttpClient\Plugin; use Http\Client\Common\Plugin\Journal; -use Http\Client\Exception; +use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -32,7 +32,7 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons $this->lastResponse = $response; } - public function addFailure(RequestInterface $request, Exception $exception) + public function addFailure(RequestInterface $request, ClientExceptionInterface $exception) { } } diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index 2c91bf74f3b..c5913d4d104 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -3,6 +3,7 @@ namespace Github\HttpClient\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -25,7 +26,7 @@ public function __construct($path) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $currentPath = $request->getUri()->getPath(); if (strpos($currentPath, $this->path) !== 0) { diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index e4ce3ae9171..ecc4ed383f8 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -4,6 +4,7 @@ use Github\Api\AbstractApi; use GuzzleHttp\Psr7\Response; +use Http\Client\Common\HttpMethodsClientInterface; class AbstractApiTest extends TestCase { @@ -213,9 +214,7 @@ protected function getClientMock() protected function getHttpMethodsMock(array $methods = []) { $methods = array_merge(['sendRequest'], $methods); - $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) - ->disableOriginalConstructor() - ->setMethods($methods) + $mock = $this->getMockBuilder(HttpMethodsClientInterface::class) ->getMock(); $mock ->expects($this->any()) diff --git a/test/Github/Tests/HttpClient/PathPrependTest.php b/test/Github/Tests/HttpClient/PathPrependTest.php index fdfe180980a..3504073a933 100644 --- a/test/Github/Tests/HttpClient/PathPrependTest.php +++ b/test/Github/Tests/HttpClient/PathPrependTest.php @@ -4,6 +4,8 @@ use Github\HttpClient\Plugin\PathPrepend; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\Response; +use Http\Promise\FulfilledPromise; use PHPUnit\Framework\TestCase; /** @@ -22,6 +24,8 @@ public function testPathIsPrepended($uri, $expectedPath) $newRequest = null; $plugin->handleRequest($request, function ($request) use (&$newRequest) { $newRequest = $request; + + return new FulfilledPromise(new Response()); }, function () { throw new \RuntimeException('Did not expect plugin to call first'); }); diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index fd83e88c2f4..457d979093f 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -4,8 +4,9 @@ use Github\Exception\ExceptionInterface; use Github\HttpClient\Plugin\GithubExceptionThrower; -use GuzzleHttp\Promise\FulfilledPromise; use GuzzleHttp\Psr7\Response; +use Http\Promise\FulfilledPromise; +use Http\Promise\Promise; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -25,11 +26,11 @@ public function testHandleRequest(ResponseInterface $response, ExceptionInterfac /** @var RequestInterface $request */ $request = $this->getMockForAbstractClass(RequestInterface::class); - $promise = $this->getMockBuilder(FulfilledPromise::class)->disableOriginalConstructor()->getMock(); + $promise = $this->getMockBuilder(Promise::class)->getMock(); $promise->expects($this->once()) ->method('then') ->willReturnCallback(function ($callback) use ($response) { - return $callback($response); + return new FulfilledPromise($callback($response)); }); $plugin = new GithubExceptionThrower();