From 530798662c7371f42c1b03212239513883dbaeaf Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 31 Oct 2018 10:49:43 +0100 Subject: [PATCH 1/4] Allow HTTPlug 2 (and hence PSR-18) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 028f1bb..97141f3 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": "^5.5 || ^7.0" }, "require-dev": { - "php-http/httplug": "^1.0", + "php-http/httplug": "^1.0|^2.0", "php-http/message-factory": "^1.0", "puli/composer-plugin": "1.0.0-beta10", "phpspec/phpspec": "^2.4", From a1d8452aec5e996a26420b7a6ff79e63840cecb8 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 31 Oct 2018 11:14:18 +0100 Subject: [PATCH 2/4] Implement a PSR-18 compliant client stub --- spec/HttpClientDiscoverySpec.php | 24 +++++++++++++++++++----- spec/Stub/PSR18ClientStub.php | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 spec/Stub/PSR18ClientStub.php diff --git a/spec/HttpClientDiscoverySpec.php b/spec/HttpClientDiscoverySpec.php index c9f9809..f778aa3 100644 --- a/spec/HttpClientDiscoverySpec.php +++ b/spec/HttpClientDiscoverySpec.php @@ -12,6 +12,9 @@ use Puli\Repository\Api\ResourceRepository; use PhpSpec\ObjectBehavior; use spec\Http\Discovery\Helper\DiscoveryHelper; +use Http\Discovery\HttpClientDiscovery; +use spec\Http\Discovery\Stub\HttpClientStub; +use spec\Http\Discovery\Stub\PSR18ClientStub; class HttpClientDiscoverySpec extends ObjectBehavior { @@ -23,23 +26,34 @@ function let() function it_is_initializable() { - $this->shouldHaveType('Http\Discovery\HttpClientDiscovery'); + $this->shouldHaveType(HttpClientDiscovery::class); } function it_is_a_class_discovery() { - $this->shouldHaveType('Http\Discovery\ClassDiscovery'); + $this->shouldHaveType(ClassDiscovery::class); } - function it_finds_a_http_client(DiscoveryStrategy $strategy) { + function it_finds_a_http_client(DiscoveryStrategy $strategy) + { + $candidate = ['class' => HttpClientStub::class, 'condition' => true]; + if ($this->psr18IsInUse()) { + $candidate['class'] = PSR18ClientStub::class; + } - $candidate = ['class' => 'spec\Http\Discovery\Stub\HttpClientStub', 'condition' => true]; DiscoveryHelper::setClasses(HttpClient::class, [$candidate]); - $this->find()->shouldImplement('Http\Client\HttpClient'); + $this->find()->shouldImplement(HttpClient::class); } function it_throw_exception(DiscoveryStrategy $strategy) { $this->shouldThrow(NotFoundException::class)->duringFind(); } + + private function psr18IsInUse() + { + $reflection = new \ReflectionMethod(HttpClient::class, 'sendRequest'); + + return $reflection->hasReturnType(); + } } diff --git a/spec/Stub/PSR18ClientStub.php b/spec/Stub/PSR18ClientStub.php new file mode 100644 index 0000000..cf3aa0c --- /dev/null +++ b/spec/Stub/PSR18ClientStub.php @@ -0,0 +1,14 @@ + Date: Wed, 31 Oct 2018 11:17:42 +0100 Subject: [PATCH 3/4] Fix build for PHP < 7 --- spec/HttpClientDiscoverySpec.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/HttpClientDiscoverySpec.php b/spec/HttpClientDiscoverySpec.php index f778aa3..a5d4259 100644 --- a/spec/HttpClientDiscoverySpec.php +++ b/spec/HttpClientDiscoverySpec.php @@ -52,6 +52,10 @@ function it_throw_exception(DiscoveryStrategy $strategy) { private function psr18IsInUse() { + if (PHP_MAJOR_VERSION < 7) { + return false; + } + $reflection = new \ReflectionMethod(HttpClient::class, 'sendRequest'); return $reflection->hasReturnType(); From 9a4bb500370d1c34dacb08286c0d77b56b9708d7 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 31 Oct 2018 11:23:54 +0100 Subject: [PATCH 4/4] Update changelog [skip CI] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a7d586..d803fbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +### Added + +- Support for `php-http/httplug` version 2.0, hence supporting PSR-18 + ## 1.5.0 - 2018-xx-xx ### Added