1212use Puli \Repository \Api \ResourceRepository ;
1313use PhpSpec \ObjectBehavior ;
1414use 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
1619class 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}
0 commit comments