Skip to content

Commit

Permalink
update httplug to 2.0 and related package
Browse files Browse the repository at this point in the history
  • Loading branch information
tzmfreedom committed Feb 8, 2019
1 parent 7e67b4c commit 4956673
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -11,8 +11,6 @@ env:
- TEST_COMMAND="vendor/bin/phpunit --verbose --coverage-text"

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lib/Github/HttpClient/Plugin/Authentication.php
Expand Up @@ -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;

/**
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Github/HttpClient/Plugin/History.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
}
}
3 changes: 2 additions & 1 deletion lib/Github/HttpClient/Plugin/PathPrepend.php
Expand Up @@ -3,6 +3,7 @@
namespace Github\HttpClient\Plugin;

use Http\Client\Common\Plugin;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;

/**
Expand All @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions test/Github/Tests/Api/AbstractApiTest.php
Expand Up @@ -4,6 +4,7 @@

use Github\Api\AbstractApi;
use GuzzleHttp\Psr7\Response;
use Http\Client\Common\HttpMethodsClientInterface;

class AbstractApiTest extends TestCase
{
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions test/Github/Tests/HttpClient/PathPrependTest.php
Expand Up @@ -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;

/**
Expand All @@ -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');
});
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 4956673

Please sign in to comment.