diff --git a/.travis.yml b/.travis.yml index 2d3930d..091065e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,13 +20,15 @@ env: branches: except: - - /^analysis-.*$/ + - /^patch-.*$/ matrix: fast_finish: true include: - - php: 5.5 + - php: 7.1 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" + - php: 5.5 + env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" before_install: - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 6713b6d..a2899bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 1.2.0 - unreleased + +### Added + +- Support for HTTPlug 2.0. +- Support for php-http/client-common 2.0. + ## 1.1.0 - 2018-01-08 ### Added diff --git a/composer.json b/composer.json index 5eb00e6..afee334 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,8 @@ ], "require": { "php": "^5.5 || ^7.0", - "php-http/httplug": "^1.0", - "php-http/client-common": "^1.1 || ^2.0", + "php-http/httplug": "^1.0 || ^2.0", + "php-http/client-common": "^1.9 || ^2.0", "php-http/discovery": "^1.0", "php-http/message-factory": "^1.0" }, diff --git a/spec/ClientSpec.php b/spec/ClientSpec.php index f900865..dbead07 100644 --- a/spec/ClientSpec.php +++ b/spec/ClientSpec.php @@ -2,7 +2,10 @@ namespace spec\Http\Mock; +use Http\Client\HttpAsyncClient; +use Http\Client\HttpClient; use Http\Message\ResponseFactory; +use Http\Mock\Client; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; @@ -16,17 +19,17 @@ function let(ResponseFactory $responseFactory) function it_is_initializable() { - $this->shouldHaveType('Http\Mock\Client'); + $this->shouldHaveType(Client::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_returns_a_response_for_a_request(RequestInterface $request, ResponseInterface $response) @@ -67,10 +70,18 @@ function it_creates_an_empty_response_when_none_is_added( $this->sendRequest($request)->shouldReturn($response); } - function it_returns_the_last_request(RequestInterface $request) + function it_returns_the_last_request(RequestInterface $request, ResponseInterface $response) { + // we need to set something that sendRequest can return. + $this->addResponse($response); + $this->sendRequest($request); $this->getLastRequest()->shouldReturn($request); } + + function it_returns_false_when_there_is_no_last_request() + { + $this->getLastRequest()->shouldReturn(false); + } } diff --git a/src/Client.php b/src/Client.php index 3f34b0d..998517d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -3,6 +3,7 @@ namespace Http\Mock; use Http\Client\Common\HttpAsyncClientEmulator; +use Http\Client\Common\VersionBridgeClient; use Http\Client\Exception; use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; @@ -12,17 +13,17 @@ use Psr\Http\Message\ResponseInterface; /** - * HTTP client mock. + * An implementation of the HTTP client that is useful for automated tests. * - * This mock is most useful in tests. It does not send requests but stores them - * for later retrieval. Additionally, you can set an exception to test - * exception handling. + * This mock does not send requests but stores them for later retrieval. + * You can configure the mock with responses to return and/or exceptions to throw. * * @author David de Boer */ class Client implements HttpClient, HttpAsyncClient { use HttpAsyncClientEmulator; + use VersionBridgeClient; /** * @var ResponseFactory @@ -54,9 +55,6 @@ class Client implements HttpClient, HttpAsyncClient */ private $defaultException; - /** - * @param ResponseFactory|null $responseFactory - */ public function __construct(ResponseFactory $responseFactory = null) { $this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find(); @@ -65,7 +63,7 @@ public function __construct(ResponseFactory $responseFactory = null) /** * {@inheritdoc} */ - public function sendRequest(RequestInterface $request) + public function doSendRequest(RequestInterface $request) { $this->requests[] = $request; @@ -91,8 +89,6 @@ public function sendRequest(RequestInterface $request) /** * Adds an exception that will be thrown. - * - * @param \Exception $exception */ public function addException(\Exception $exception) { @@ -103,8 +99,6 @@ public function addException(\Exception $exception) * Sets the default exception to throw when the list of added exceptions and responses is exhausted. * * If both a default exception and a default response are set, the exception will be thrown. - * - * @param \Exception|null $defaultException */ public function setDefaultException(\Exception $defaultException = null) { @@ -112,9 +106,7 @@ public function setDefaultException(\Exception $defaultException = null) } /** - * Adds a response that will be returned. - * - * @param ResponseInterface $response + * Adds a response that will be returned in first in first out order. */ public function addResponse(ResponseInterface $response) { @@ -123,8 +115,6 @@ public function addResponse(ResponseInterface $response) /** * Sets the default response to be returned when the list of added exceptions and responses is exhausted. - * - * @param ResponseInterface|null $defaultResponse */ public function setDefaultResponse(ResponseInterface $defaultResponse = null) { @@ -141,9 +131,6 @@ public function getRequests() return $this->requests; } - /** - * @return RequestInterface|false - */ public function getLastRequest() { return end($this->requests);