|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Http\Client\Common; |
| 4 | + |
| 5 | +use Http\Client\Common\HttpAsyncClientDecorator; |
| 6 | +use Http\Client\Common\HttpClientDecorator; |
| 7 | +use Http\Client\Common\HttpClientFlexible; |
| 8 | +use Http\Client\HttpAsyncClient; |
| 9 | +use Http\Client\HttpClient; |
| 10 | +use PhpSpec\ObjectBehavior; |
| 11 | + |
| 12 | +class HttpClientFlexibleSpec extends ObjectBehavior |
| 13 | +{ |
| 14 | + function let(HttpClient $httpClient) |
| 15 | + { |
| 16 | + $this->beAnInstanceOf( |
| 17 | + 'spec\Http\Client\Common\HttpClientFlexibleStub', [ |
| 18 | + $httpClient |
| 19 | + ] |
| 20 | + ); |
| 21 | + } |
| 22 | + |
| 23 | + function it_is_initializable() |
| 24 | + { |
| 25 | + $this->shouldHaveType('Http\Client\Common\HttpClientFlexible'); |
| 26 | + } |
| 27 | + |
| 28 | + function it_is_an_http_client() |
| 29 | + { |
| 30 | + $this->shouldImplement('Http\Client\HttpClient'); |
| 31 | + } |
| 32 | + |
| 33 | + function it_is_an_async_http_client() |
| 34 | + { |
| 35 | + $this->shouldImplement('Http\Client\HttpAsyncClient'); |
| 36 | + } |
| 37 | + |
| 38 | + function it_throw_exception_if_invalid_client() |
| 39 | + { |
| 40 | + $httpClient = null; |
| 41 | + |
| 42 | + $this->shouldThrow('\LogicException')->during('__construct', [$httpClient]); |
| 43 | + } |
| 44 | + |
| 45 | + function it_emulates_an_async_client(HttpClient $httpClient) |
| 46 | + { |
| 47 | + $this->beConstructedWith($httpClient); |
| 48 | + |
| 49 | + $this->getClient()->shouldImplement('Http\Client\HttpClient'); |
| 50 | + $this->getAsyncClient()->shouldImplement('Http\Client\HttpAsyncClient'); |
| 51 | + $this->getAsyncClient()->shouldImplement('Http\Client\Common\EmulatedHttpAsyncClient'); |
| 52 | + } |
| 53 | + |
| 54 | + function it_emulates_a_client(HttpAsyncClient $httpAsyncClient) |
| 55 | + { |
| 56 | + $this->beConstructedWith($httpAsyncClient); |
| 57 | + |
| 58 | + $this->getClient()->shouldImplement('Http\Client\HttpClient'); |
| 59 | + $this->getAsyncClient()->shouldImplement('Http\Client\HttpAsyncClient'); |
| 60 | + $this->getClient()->shouldImplement('Http\Client\Common\EmulatedHttpClient'); |
| 61 | + } |
| 62 | + |
| 63 | + function it_does_not_emulates_a_client(HttpClientFull $httpClient) |
| 64 | + { |
| 65 | + $this->beConstructedWith($httpClient); |
| 66 | + |
| 67 | + $this->getClient()->shouldImplement('Http\Client\HttpClient'); |
| 68 | + $this->getAsyncClient()->shouldImplement('Http\Client\HttpAsyncClient'); |
| 69 | + $this->getClient()->shouldImplement('spec\Http\Client\Common\HttpClientFull'); |
| 70 | + $this->getAsyncClient()->shouldImplement('spec\Http\Client\Common\HttpClientFull'); |
| 71 | + $this->getClient()->shouldNotImplement('Http\Client\Common\EmulatedHttpClient'); |
| 72 | + $this->getAsyncClient()->shouldNotImplement('Http\Client\Common\EmulatedHttpAsyncClient'); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +class HttpClientFull implements HttpClient, HttpAsyncClient |
| 77 | +{ |
| 78 | + use HttpClientDecorator; |
| 79 | + use HttpAsyncClientDecorator; |
| 80 | +} |
| 81 | + |
| 82 | +class HttpClientFlexibleStub extends HttpClientFlexible |
| 83 | +{ |
| 84 | + public function getClient() |
| 85 | + { |
| 86 | + return $this->httpClient; |
| 87 | + } |
| 88 | + |
| 89 | + public function getAsyncClient() |
| 90 | + { |
| 91 | + return $this->httpAsyncClient; |
| 92 | + } |
| 93 | +} |
0 commit comments