|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Http\Client\Common; |
| 4 | + |
| 5 | +use Http\Client\Common\RequestMatcher; |
| 6 | +use Http\Client\HttpAsyncClient; |
| 7 | +use Http\Client\HttpClient; |
| 8 | +use Http\Promise\Promise; |
| 9 | +use PhpSpec\ObjectBehavior; |
| 10 | +use Psr\Http\Message\RequestInterface; |
| 11 | +use Psr\Http\Message\ResponseInterface; |
| 12 | + |
| 13 | +class HttpClientRouterSpec extends ObjectBehavior |
| 14 | +{ |
| 15 | + function it_is_initializable() |
| 16 | + { |
| 17 | + $this->shouldHaveType('Http\Client\Common\HttpClientRouter'); |
| 18 | + } |
| 19 | + |
| 20 | + function it_is_an_http_client() |
| 21 | + { |
| 22 | + $this->shouldImplement('Http\Client\HttpClient'); |
| 23 | + } |
| 24 | + |
| 25 | + function it_is_an_async_http_client() |
| 26 | + { |
| 27 | + $this->shouldImplement('Http\Client\HttpAsyncClient'); |
| 28 | + } |
| 29 | + |
| 30 | + function it_send_request(RequestMatcher $matcher, HttpClient $client, RequestInterface $request, ResponseInterface $response) |
| 31 | + { |
| 32 | + $this->addClient($client, $matcher); |
| 33 | + $matcher->matches($request)->willReturn(true); |
| 34 | + $client->sendRequest($request)->willReturn($response); |
| 35 | + |
| 36 | + $this->sendRequest($request)->shouldReturn($response); |
| 37 | + } |
| 38 | + |
| 39 | + function it_send_async_request(RequestMatcher $matcher, HttpAsyncClient $client, RequestInterface $request, Promise $promise) |
| 40 | + { |
| 41 | + $this->addClient($client, $matcher); |
| 42 | + $matcher->matches($request)->willReturn(true); |
| 43 | + $client->sendAsyncRequest($request)->willReturn($promise); |
| 44 | + |
| 45 | + $this->sendAsyncRequest($request)->shouldReturn($promise); |
| 46 | + } |
| 47 | + |
| 48 | + function it_throw_exception_on_send_request(RequestMatcher $matcher, HttpClient $client, RequestInterface $request) |
| 49 | + { |
| 50 | + $this->addClient($client, $matcher); |
| 51 | + $matcher->matches($request)->willReturn(false); |
| 52 | + |
| 53 | + $this->shouldThrow('Http\Client\Exception\RequestException')->duringSendRequest($request); |
| 54 | + } |
| 55 | + |
| 56 | + function it_throw_exception_on_send_async_request(RequestMatcher $matcher, HttpAsyncClient $client, RequestInterface $request) |
| 57 | + { |
| 58 | + $this->addClient($client, $matcher); |
| 59 | + $matcher->matches($request)->willReturn(false); |
| 60 | + |
| 61 | + $this->shouldThrow('Http\Client\Exception\RequestException')->duringSendAsyncRequest($request); |
| 62 | + } |
| 63 | +} |
0 commit comments