12
12
use Puli \Repository \Api \ResourceRepository ;
13
13
use PhpSpec \ObjectBehavior ;
14
14
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 ;
15
18
16
19
class HttpClientDiscoverySpec extends ObjectBehavior
17
20
{
@@ -23,23 +26,34 @@ function let()
23
26
24
27
function it_is_initializable ()
25
28
{
26
- $ this ->shouldHaveType (' Http\Discovery\ HttpClientDiscovery' );
29
+ $ this ->shouldHaveType (HttpClientDiscovery::class );
27
30
}
28
31
29
32
function it_is_a_class_discovery ()
30
33
{
31
- $ this ->shouldHaveType (' Http\Discovery\ ClassDiscovery' );
34
+ $ this ->shouldHaveType (ClassDiscovery::class );
32
35
}
33
36
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
+ }
35
43
36
- $ candidate = ['class ' => 'spec\Http\Discovery\Stub\HttpClientStub ' , 'condition ' => true ];
37
44
DiscoveryHelper::setClasses (HttpClient::class, [$ candidate ]);
38
45
39
- $ this ->find ()->shouldImplement (' Http\Client\ HttpClient' );
46
+ $ this ->find ()->shouldImplement (HttpClient::class );
40
47
}
41
48
42
49
function it_throw_exception (DiscoveryStrategy $ strategy ) {
43
50
$ this ->shouldThrow (NotFoundException::class)->duringFind ();
44
51
}
52
+
53
+ private function psr18IsInUse ()
54
+ {
55
+ $ reflection = new \ReflectionMethod (HttpClient::class, 'sendRequest ' );
56
+
57
+ return $ reflection ->hasReturnType ();
58
+ }
45
59
}
0 commit comments