|
2 | 2 |
|
3 | 3 | namespace spec\Http\Client\Exception; |
4 | 4 |
|
5 | | -use Http\Client\Exception\TransferException; |
6 | | -use Psr\Http\Message\ResponseInterface; |
| 5 | +use Http\Client\BatchResult; |
| 6 | +use Http\Client\Exception; |
| 7 | +use Psr\Http\Message\RequestInterface; |
7 | 8 | use PhpSpec\ObjectBehavior; |
8 | 9 |
|
9 | 10 | class BatchExceptionSpec extends ObjectBehavior |
10 | 11 | { |
11 | | - function let(TransferException $e, ResponseInterface $response) |
| 12 | + function it_is_initializable() |
12 | 13 | { |
13 | | - $this->beConstructedWith([$e], [$response]); |
| 14 | + $this->shouldHaveType('Http\Client\Exception\BatchException'); |
14 | 15 | } |
15 | 16 |
|
16 | | - function it_is_initializable() |
| 17 | + function it_is_an_exception() |
17 | 18 | { |
18 | | - $this->shouldHaveType('Http\Client\Exception\BatchException'); |
| 19 | + $this->shouldImplement('Http\Client\Exception'); |
| 20 | + $this->shouldHaveType('Exception'); |
| 21 | + } |
| 22 | + |
| 23 | + function it_has_a_result() |
| 24 | + { |
| 25 | + $this->setResult($result = new BatchResult()); |
| 26 | + $this->getResult()->shouldReturn($result); |
| 27 | + } |
| 28 | + |
| 29 | + function it_throws_an_exception_if_the_result_is_already_set() |
| 30 | + { |
| 31 | + $this->getResult()->shouldHaveType('Http\Client\BatchResult'); |
| 32 | + $this->shouldThrow('Http\Client\Exception\InvalidArgumentException')->duringSetResult(new BatchResult()); |
19 | 33 | } |
20 | 34 |
|
21 | | - function it_is_a_transfer_exception() |
| 35 | + function it_has_an_exception_for_a_request(RequestInterface $request, Exception $exception) |
22 | 36 | { |
23 | | - $this->shouldHaveType('Http\Client\Exception\TransferException'); |
| 37 | + $this->shouldThrow('Http\Client\Exception\UnexpectedValueException')->duringGetExceptionFor($request); |
| 38 | + $this->hasExceptionFor($request)->shouldReturn(false); |
| 39 | + |
| 40 | + $this->addException($request, $exception); |
| 41 | + |
| 42 | + $this->getExceptionFor($request)->shouldReturn($exception); |
| 43 | + $this->hasExceptionFor($request)->shouldReturn(true); |
24 | 44 | } |
25 | 45 |
|
26 | | - function it_has_exceptions(TransferException $e, TransferException $e2) |
| 46 | + function it_has_exceptions(RequestInterface $request, Exception $exception) |
27 | 47 | { |
28 | | - $this->getExceptions()->shouldReturn([$e]); |
29 | | - $this->hasException($e)->shouldReturn(true); |
30 | | - $this->hasException($e2)->shouldReturn(false); |
31 | | - $this->hasExceptions()->shouldReturn(true); |
| 48 | + $this->getExceptions()->shouldReturn([]); |
| 49 | + |
| 50 | + $this->addException($request, $exception); |
| 51 | + |
| 52 | + $this->getExceptions()->shouldReturn([$exception]); |
32 | 53 | } |
33 | 54 |
|
34 | | - function it_has_responses(ResponseInterface $response, ResponseInterface $response2) |
| 55 | + function it_checks_if_a_request_failed(RequestInterface $request, Exception $exception) |
35 | 56 | { |
36 | | - $this->getResponses()->shouldReturn([$response]); |
37 | | - $this->hasResponse($response)->shouldReturn(true); |
38 | | - $this->hasResponse($response2)->shouldReturn(false); |
39 | | - $this->hasResponses()->shouldReturn(true); |
| 57 | + $this->isSuccessful($request)->shouldReturn(false); |
| 58 | + $this->isFailed($request)->shouldReturn(false); |
| 59 | + |
| 60 | + $this->addException($request, $exception); |
| 61 | + |
| 62 | + $this->isSuccessful($request)->shouldReturn(false); |
| 63 | + $this->isFailed($request)->shouldReturn(true); |
40 | 64 | } |
41 | 65 | } |
0 commit comments