From 7bedb5bba2fe90fef6fbcd1001d74fbe7ec1f630 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Mon, 21 Jan 2019 19:57:18 +0100 Subject: [PATCH 1/4] Make httplug optional, depends on psr18 --- CHANGELOG.md | 6 +++++- composer.json | 11 ++++++++--- src/HttpAsyncClientTest.php | 5 +---- src/HttpBaseTest.php | 23 ++++------------------- src/HttpClientTest.php | 9 +++------ src/HttpFeatureTest.php | 19 ++----------------- src/ResultPrinter.php | 37 ++++++++++--------------------------- 7 files changed, 33 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06d0643..1ec48da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [3.0.0] - Unreleased + +- Only support httplug 2.0 and psr18 +- Httplug 2.0 is now optional (only require it if you need to test async) +- HttpClientTest now rely only on PSR18 (no need for httplug) ## [2.0.1] - 2018-12-27 diff --git a/composer.json b/composer.json index a3ba241..efd67de 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,18 @@ } ], "require": { - "php": ">=5.4", - "phpunit/phpunit": "^4.8.35 || ^5.4.3 || ^6.0 || ^7.0", - "php-http/httplug": "^1.0 || ^2.0", + "php": ">=7.1", + "phpunit/phpunit": "^7.0", "php-http/message": "^1.0", "guzzlehttp/psr7": "^1.0", "th3n3rd/cartesian-product": "^0.3" }, + "suggest": { + "php-http/httplug": "To test async client" + }, + "require-dev": { + "php-http/httplug": "^2.0" + }, "autoload": { "psr-4": { "Http\\Client\\Tests\\": "src/" diff --git a/src/HttpAsyncClientTest.php b/src/HttpAsyncClientTest.php index 4c0c5f0..391053d 100644 --- a/src/HttpAsyncClientTest.php +++ b/src/HttpAsyncClientTest.php @@ -27,10 +27,7 @@ protected function tearDown() unset($this->httpAdapter); } - /** - * @return HttpAsyncClient - */ - abstract protected function createHttpAsyncClient(); + abstract protected function createHttpAsyncClient(): HttpAsyncClient; public function testSuccessiveCallMustUseResponseInterface() { diff --git a/src/HttpBaseTest.php b/src/HttpBaseTest.php index a3f3359..6a8f7dc 100644 --- a/src/HttpBaseTest.php +++ b/src/HttpBaseTest.php @@ -59,10 +59,7 @@ public static function tearDownAfterClass() } } - /** - * @return array - */ - public function requestProvider() + public function requestProvider(): array { $sets = [ 'methods' => $this->getMethods(), @@ -85,10 +82,7 @@ public function requestProvider() }); } - /** - * @return array - */ - public function requestWithOutcomeProvider() + public function requestWithOutcomeProvider(): array { $sets = [ 'urisAndOutcomes' => $this->getUrisAndOutcomes(), @@ -102,10 +96,7 @@ public function requestWithOutcomeProvider() return $cartesianProduct->compute(); } - /** - * @return array - */ - private function getMethods() + private function getMethods(): array { return [ 'GET', @@ -211,14 +202,8 @@ private function getData() return ['param1' => 'foo', 'param2' => ['bar', ['baz']]]; } - /** - * @param ResponseInterface $response - * @param array $options - */ - protected function assertResponse($response, array $options = []) + protected function assertResponse(ResponseInterface $response, array $options = []) { - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); - $options = array_merge($this->defaultOptions, $options); // The response version may be greater or equal to the request version. See https://tools.ietf.org/html/rfc2145#section-2.3 diff --git a/src/HttpClientTest.php b/src/HttpClientTest.php index a63d92c..a7a2609 100644 --- a/src/HttpClientTest.php +++ b/src/HttpClientTest.php @@ -2,7 +2,7 @@ namespace Http\Client\Tests; -use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; /** * @author GeLo @@ -10,7 +10,7 @@ abstract class HttpClientTest extends HttpBaseTest { /** - * @var HttpClient + * @var ClientInterface */ protected $httpAdapter; @@ -30,10 +30,7 @@ protected function tearDown() unset($this->httpAdapter); } - /** - * @return HttpClient - */ - abstract protected function createHttpAdapter(); + abstract protected function createHttpAdapter(): ClientInterface; /** * @dataProvider requestProvider diff --git a/src/HttpFeatureTest.php b/src/HttpFeatureTest.php index d1aa021..fd56a57 100644 --- a/src/HttpFeatureTest.php +++ b/src/HttpFeatureTest.php @@ -2,7 +2,7 @@ namespace Http\Client\Tests; -use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; use Http\Message\MessageFactory; use Http\Message\MessageFactory\GuzzleMessageFactory; use PHPUnit\Framework\TestCase; @@ -22,10 +22,7 @@ public static function setUpBeforeClass() self::$messageFactory = new GuzzleMessageFactory(); } - /** - * @return HttpClient - */ - abstract protected function createClient(); + abstract protected function createClient(): ClientInterface; /** * @feature Send a GET Request @@ -39,7 +36,6 @@ public function testGet() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); } @@ -58,7 +54,6 @@ public function testPost() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); $contents = json_decode($response->getBody()->__toString()); @@ -78,7 +73,6 @@ public function testPatch() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); } @@ -94,7 +88,6 @@ public function testPut() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); } @@ -110,7 +103,6 @@ public function testDelete() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); } @@ -129,7 +121,6 @@ public function testAutoSetContentLength() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); $contents = json_decode($response->getBody()->__toString()); @@ -149,7 +140,6 @@ public function testEncoding() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); $this->assertContains('€', $response->getBody()->__toString()); } @@ -166,7 +156,6 @@ public function testGzip() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); $this->assertContains('gzip', $response->getBody()->__toString()); } @@ -183,7 +172,6 @@ public function testDeflate() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); $this->assertContains('deflate', $response->getBody()->__toString()); } @@ -200,7 +188,6 @@ public function testRedirect() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); } @@ -216,7 +203,6 @@ public function testChunked() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); $content = @json_decode($response->getBody()->__toString()); @@ -236,7 +222,6 @@ public function testSsl() $response = $this->createClient()->sendRequest($request); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertSame(200, $response->getStatusCode()); } } diff --git a/src/ResultPrinter.php b/src/ResultPrinter.php index 5ea6c0d..497f43f 100644 --- a/src/ResultPrinter.php +++ b/src/ResultPrinter.php @@ -3,36 +3,19 @@ namespace Http\Client\Tests; use PHPUnit\Framework\Test; +use PHPUnit\TextUI\ResultPrinter as BaseResultPrinter; -// If PHPUnit 6 -if (class_exists('\\PHPUnit\\TextUI\\ResultPrinter')) { - class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter - { - use FeatureTestListener; - - public function startTest(Test $test) - { - return $this->doStartTest($test); - } +class ResultPrinter extends BaseResultPrinter +{ + use FeatureTestListener; - public function endTest(Test $test, $time) - { - return $this->doEndTest($test, $time); - } - } -} else { - class ResultPrinter extends \PHPUnit_TextUI_ResultPrinter + public function startTest(Test $test): void { - use FeatureTestListener; - - public function startTest(\PHPUnit_Framework_Test $test) - { - return $this->doStartTest($test); - } + return $this->doStartTest($test); + } - public function endTest(\PHPUnit_Framework_Test $test, $time) - { - return $this->doEndTest($test, $time); - } + public function endTest(Test $test, float $time): void + { + return $this->doEndTest($test, $time); } } From 30799d85532513530dfb2ae9dd32ba5c673968c4 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Tue, 22 Jan 2019 10:51:43 +0100 Subject: [PATCH 2/4] Fix typo --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec48da..1700a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [3.0.0] - Unreleased -- Only support httplug 2.0 and psr18 -- Httplug 2.0 is now optional (only require it if you need to test async) -- HttpClientTest now rely only on PSR18 (no need for httplug) +- Only support HTTPlug 2.0 and PSR-18 +- HTTPlug 2.0 is now optional (only require it if you need to test async) +- HttpClientTest now relies only on PSR-18 (no need for HTTPlug) ## [2.0.1] - 2018-12-27 From 2ff33b4c669aeb84f3fc517cae0b726c76753eec Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Tue, 22 Jan 2019 14:11:02 +0100 Subject: [PATCH 3/4] Update branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index efd67de..4b76f41 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ ], "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } } } From 032a7311d5577c3bc767e269fd997683427b56e6 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Sat, 16 Feb 2019 22:49:23 +0100 Subject: [PATCH 4/4] Update php version constraint --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4b76f41..12019ca 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.1", + "php": "^7.1", "phpunit/phpunit": "^7.0", "php-http/message": "^1.0", "guzzlehttp/psr7": "^1.0",