From 0fae9139ce12c6c902e98d36d0cbe27f59dc5d46 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 5 Aug 2019 22:03:16 +0200 Subject: [PATCH] Allow httplug 2.0 --- composer.json | 8 ++--- .../HttpClient/Plugin/Authentication.php | 4 ++- .../Plugin/GithubExceptionThrower.php | 4 ++- lib/Github/HttpClient/Plugin/History.php | 7 ++-- lib/Github/HttpClient/Plugin/HistoryTrait.php | 32 +++++++++++++++++++ lib/Github/HttpClient/Plugin/PathPrepend.php | 4 ++- test/Github/Tests/Api/AbstractApiTest.php | 30 ++++++----------- .../Tests/HttpClient/PathPrependTest.php | 2 +- .../Plugin/GithubExceptionThrowerTest.php | 2 +- 9 files changed, 59 insertions(+), 34 deletions(-) create mode 100644 lib/Github/HttpClient/Plugin/HistoryTrait.php diff --git a/composer.json b/composer.json index 1e701df8b7c..ad59c685441 100644 --- a/composer.json +++ b/composer.json @@ -20,16 +20,16 @@ "php": "^5.6 || ^7.0", "psr/http-message": "^1.0", "psr/cache": "^1.0", - "php-http/httplug": "^1.1", + "php-http/httplug": "^1.1 || ^2.0", "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", - "php-http/client-common": "^1.6", + "php-http/client-common": "^1.6 || ^2.0", "php-http/cache-plugin": "^1.4" }, "require-dev": { "phpunit/phpunit": "^5.5 || ^6.0", - "php-http/guzzle6-adapter": "^1.0", - "php-http/mock-client": "^1.0", + "php-http/guzzle6-adapter": "^1.0 || ^2.0", + "php-http/mock-client": "^1.2", "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..0ab09ab20ba 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -14,6 +14,8 @@ */ class Authentication implements Plugin { + use Plugin\VersionBridgePlugin; + private $tokenOrLogin; private $password; private $method; @@ -28,7 +30,7 @@ public function __construct($tokenOrLogin, $password, $method) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { 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..933c06a5817 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -18,10 +18,12 @@ */ class GithubExceptionThrower implements Plugin { + use Plugin\VersionBridgePlugin; + /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { 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..0f59bbb65f9 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -3,7 +3,6 @@ namespace Github\HttpClient\Plugin; use Http\Client\Common\Plugin\Journal; -use Http\Client\Exception; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -14,6 +13,8 @@ */ class History implements Journal { + use HistoryTrait; + /** * @var ResponseInterface */ @@ -31,8 +32,4 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons { $this->lastResponse = $response; } - - public function addFailure(RequestInterface $request, Exception $exception) - { - } } diff --git a/lib/Github/HttpClient/Plugin/HistoryTrait.php b/lib/Github/HttpClient/Plugin/HistoryTrait.php new file mode 100644 index 00000000000..fbc5335d318 --- /dev/null +++ b/lib/Github/HttpClient/Plugin/HistoryTrait.php @@ -0,0 +1,32 @@ +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..c2d875664ff 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 { @@ -212,26 +213,15 @@ protected function getClientMock() */ protected function getHttpMethodsMock(array $methods = []) { - $methods = array_merge(['sendRequest'], $methods); - $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) - ->disableOriginalConstructor() - ->setMethods($methods) - ->getMock(); - $mock - ->expects($this->any()) - ->method('sendRequest'); - - return $mock; - } - - /** - * @return \Http\Client\HttpClient - */ - protected function getHttpClientMock() - { - $mock = $this->getMockBuilder(\Http\Client\HttpClient::class) - ->setMethods(['sendRequest']) - ->getMock(); + if (interface_exists(HttpMethodsClientInterface::class)) { + $mock = $this->createMock(HttpMethodsClientInterface::class); + } else { + $methods = array_merge(['sendRequest'], $methods); + $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) + ->disableOriginalConstructor() + ->setMethods($methods) + ->getMock(); + } $mock ->expects($this->any()) ->method('sendRequest'); diff --git a/test/Github/Tests/HttpClient/PathPrependTest.php b/test/Github/Tests/HttpClient/PathPrependTest.php index fdfe180980a..e5feda2cf3d 100644 --- a/test/Github/Tests/HttpClient/PathPrependTest.php +++ b/test/Github/Tests/HttpClient/PathPrependTest.php @@ -20,7 +20,7 @@ public function testPathIsPrepended($uri, $expectedPath) $plugin = new PathPrepend('/api/v3'); $newRequest = null; - $plugin->handleRequest($request, function ($request) use (&$newRequest) { + $plugin->doHandleRequest($request, function ($request) use (&$newRequest) { $newRequest = $request; }, 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..84027aa4339 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -40,7 +40,7 @@ public function testHandleRequest(ResponseInterface $response, ExceptionInterfac $this->expectExceptionMessage($exception->getMessage()); } - $plugin->handleRequest( + $plugin->doHandleRequest( $request, function (RequestInterface $request) use ($promise) { return $promise;