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 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", diff --git a/spec/HttpClientDiscoverySpec.php b/spec/HttpClientDiscoverySpec.php index c9f9809..a5d4259 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,38 @@ 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() + { + if (PHP_MAJOR_VERSION < 7) { + return false; + } + + $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 @@ +