55use Http \Client \Exception \TransferException ;
66use Http \Client \HttpClient ;
77use Http \Client \HttpAsyncClient ;
8- use Http \Client \Common \HttpClientEmulator ;
9- use Http \Client \Common \HttpAsyncClientDecorator ;
108use Http \Promise \Promise ;
119use Psr \Http \Message \RequestInterface ;
1210use Psr \Http \Message \ResponseInterface ;
1311use PhpSpec \ObjectBehavior ;
1412
15- class HttpClientEmulatorSpec extends ObjectBehavior
13+ class EmulatedHttpClientSpec extends ObjectBehavior
1614{
1715 function let (HttpAsyncClient $ httpAsyncClient )
1816 {
19- $ this ->beAnInstanceOf ( ' spec\Http\Client\Common\HttpClientEmulatorStub ' , [ $ httpAsyncClient] );
17+ $ this ->beConstructedWith ( $ httpAsyncClient );
2018 }
2119
2220 function it_is_initializable ()
2321 {
24- $ this ->shouldHaveType ('spec\ Http\Client\Common\HttpClientEmulatorStub ' );
22+ $ this ->shouldHaveType ('Http\Client\Common\EmulatedHttpClient ' );
2523 }
2624
27- function it_emulates_a_successful_request ( HttpAsyncClient $ httpAsyncClient , RequestInterface $ request , Promise $ promise , ResponseInterface $ response )
25+ function it_is_an_http_client ( )
2826 {
27+ $ this ->shouldImplement ('Http\Client\HttpClient ' );
28+ }
29+
30+ function it_is_an_async_http_client ()
31+ {
32+ $ this ->shouldImplement ('Http\Client\HttpAsyncClient ' );
33+ }
34+
35+ function it_emulates_a_successful_request (
36+ HttpAsyncClient $ httpAsyncClient ,
37+ RequestInterface $ request ,
38+ Promise $ promise ,
39+ ResponseInterface $ response
40+ ) {
2941 $ promise ->wait ()->shouldBeCalled ();
3042 $ promise ->getState ()->willReturn (Promise::FULFILLED );
3143 $ promise ->wait ()->willReturn ($ response );
@@ -45,18 +57,14 @@ function it_emulates_a_failed_request(HttpAsyncClient $httpAsyncClient, RequestI
4557
4658 $ this ->shouldThrow ('Http\Client\Exception ' )->duringSendRequest ($ request );
4759 }
48- }
4960
50- class HttpClientEmulatorStub implements HttpAsyncClient, HttpClient
51- {
52- use HttpAsyncClientDecorator;
53- use HttpClientEmulator;
61+ function it_decorates_the_underlying_client (
62+ HttpAsyncClient $ httpAsyncClient ,
63+ RequestInterface $ request ,
64+ Promise $ promise
65+ ) {
66+ $ httpAsyncClient ->sendAsyncRequest ($ request )->willReturn ($ promise );
5467
55- /**
56- * @param HttpAsyncClient $httpAsyncClient
57- */
58- public function __construct (HttpAsyncClient $ httpAsyncClient )
59- {
60- $ this ->httpAsyncClient = $ httpAsyncClient ;
68+ $ this ->sendAsyncRequest ($ request )->shouldReturn ($ promise );
6169 }
6270}
0 commit comments