Skip to content

Commit 7e9a472

Browse files
authored
Merge pull request #115 from Jean85/patch-1
Allow HTTPlug 2 (and hence PSR-18)
2 parents 5a6d803 + 9a4bb50 commit 7e9a472

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
### Added
4+
5+
- Support for `php-http/httplug` version 2.0, hence supporting PSR-18
6+
37
## 1.5.0 - 2018-xx-xx
48

59
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": "^5.5 || ^7.0"
1515
},
1616
"require-dev": {
17-
"php-http/httplug": "^1.0",
17+
"php-http/httplug": "^1.0|^2.0",
1818
"php-http/message-factory": "^1.0",
1919
"puli/composer-plugin": "1.0.0-beta10",
2020
"phpspec/phpspec": "^2.4",

spec/HttpClientDiscoverySpec.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Puli\Repository\Api\ResourceRepository;
1313
use PhpSpec\ObjectBehavior;
1414
use spec\Http\Discovery\Helper\DiscoveryHelper;
15+
use Http\Discovery\HttpClientDiscovery;
16+
use spec\Http\Discovery\Stub\HttpClientStub;
17+
use spec\Http\Discovery\Stub\PSR18ClientStub;
1518

1619
class HttpClientDiscoverySpec extends ObjectBehavior
1720
{
@@ -23,23 +26,38 @@ function let()
2326

2427
function it_is_initializable()
2528
{
26-
$this->shouldHaveType('Http\Discovery\HttpClientDiscovery');
29+
$this->shouldHaveType(HttpClientDiscovery::class);
2730
}
2831

2932
function it_is_a_class_discovery()
3033
{
31-
$this->shouldHaveType('Http\Discovery\ClassDiscovery');
34+
$this->shouldHaveType(ClassDiscovery::class);
3235
}
3336

34-
function it_finds_a_http_client(DiscoveryStrategy $strategy) {
37+
function it_finds_a_http_client(DiscoveryStrategy $strategy)
38+
{
39+
$candidate = ['class' => HttpClientStub::class, 'condition' => true];
40+
if ($this->psr18IsInUse()) {
41+
$candidate['class'] = PSR18ClientStub::class;
42+
}
3543

36-
$candidate = ['class' => 'spec\Http\Discovery\Stub\HttpClientStub', 'condition' => true];
3744
DiscoveryHelper::setClasses(HttpClient::class, [$candidate]);
3845

39-
$this->find()->shouldImplement('Http\Client\HttpClient');
46+
$this->find()->shouldImplement(HttpClient::class);
4047
}
4148

4249
function it_throw_exception(DiscoveryStrategy $strategy) {
4350
$this->shouldThrow(NotFoundException::class)->duringFind();
4451
}
52+
53+
private function psr18IsInUse()
54+
{
55+
if (PHP_MAJOR_VERSION < 7) {
56+
return false;
57+
}
58+
59+
$reflection = new \ReflectionMethod(HttpClient::class, 'sendRequest');
60+
61+
return $reflection->hasReturnType();
62+
}
4563
}

spec/Stub/PSR18ClientStub.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace spec\Http\Discovery\Stub;
4+
5+
use Http\Client\HttpClient;
6+
use Psr\Http\Message\RequestInterface;
7+
use Psr\Http\Message\ResponseInterface;
8+
9+
class PSR18ClientStub implements HttpClient
10+
{
11+
public function sendRequest(RequestInterface $request): ResponseInterface
12+
{
13+
}
14+
}

0 commit comments

Comments
 (0)