-
Notifications
You must be signed in to change notification settings - Fork 54
/
BatchClientSpec.php
36 lines (29 loc) · 1.35 KB
/
BatchClientSpec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace spec\Http\Client\Common;
use Http\Client\HttpClient;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use PhpSpec\ObjectBehavior;
use Http\Client\Common\BatchClient;
use Http\Client\Common\BatchResult;
use Http\Client\Exception\HttpException;
use Http\Client\Common\Exception\BatchException;
class BatchClientSpec extends ObjectBehavior
{
public function let(HttpClient $client)
{
$this->beAnInstanceOf(BatchClient::class, [$client]);
}
public function it_send_multiple_request_using_send_request(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response1, ResponseInterface $response2)
{
$client->sendRequest($request1)->willReturn($response1);
$client->sendRequest($request2)->willReturn($response2);
$this->sendRequests([$request1, $request2])->shouldReturnAnInstanceOf(BatchResult::class);
}
public function it_throw_batch_exception_if_one_or_more_request_failed(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response)
{
$client->sendRequest($request1)->willReturn($response);
$client->sendRequest($request2)->willThrow(HttpException::class);
$this->shouldThrow(BatchException::class)->duringSendRequests([$request1, $request2]);
}
}