This repository was archived by the owner on Jan 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathHttpMethodsClientSpec.php
116 lines (92 loc) · 3.21 KB
/
HttpMethodsClientSpec.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
namespace spec\Http\Client\Utils;
use Http\Client\BatchResult;
use Http\Client\HttpClient;
use Http\Client\Utils\HttpMethodsClient;
use Http\Message\MessageFactory;
use PhpSpec\ObjectBehavior;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
class HttpMethodsClientSpec extends ObjectBehavior
{
function let(HttpClient $client, MessageFactory $messageFactory)
{
$this->beAnInstanceOf(
'spec\Http\Client\Utils\HttpMethodsClientStub', [
$client,
$messageFactory
]
);
}
function it_sends_a_get_request()
{
$data = HttpMethodsClientStub::$requestData;
$this->get($data['uri'], $data['headers'])->shouldReturn(true);
}
function it_sends_a_head_request()
{
$data = HttpMethodsClientStub::$requestData;
$this->head($data['uri'], $data['headers'])->shouldReturn(true);
}
function it_sends_a_trace_request()
{
$data = HttpMethodsClientStub::$requestData;
$this->trace($data['uri'], $data['headers'])->shouldReturn(true);
}
function it_sends_a_post_request()
{
$data = HttpMethodsClientStub::$requestData;
$this->post($data['uri'], $data['headers'], $data['body'])->shouldReturn(true);
}
function it_sends_a_put_request()
{
$data = HttpMethodsClientStub::$requestData;
$this->put($data['uri'], $data['headers'], $data['body'])->shouldReturn(true);
}
function it_sends_a_patch_request()
{
$data = HttpMethodsClientStub::$requestData;
$this->patch($data['uri'], $data['headers'], $data['body'])->shouldReturn(true);
}
function it_sends_a_delete_request()
{
$data = HttpMethodsClientStub::$requestData;
$this->delete($data['uri'], $data['headers'], $data['body'])->shouldReturn(true);
}
function it_sends_a_options_request()
{
$data = HttpMethodsClientStub::$requestData;
$this->options($data['uri'], $data['headers'], $data['body'])->shouldReturn(true);
}
function it_sends_request_with_underlying_client(HttpClient $client, MessageFactory $messageFactory, RequestInterface $request, ResponseInterface $response)
{
$client->sendRequest($request)->shouldBeCalled()->willReturn($response);
$this->beConstructedWith($client, $messageFactory);
$this->sendRequest($request)->shouldReturn($response);
}
}
class HttpMethodsClientStub extends HttpMethodsClient
{
public static $requestData = [
'uri' => '/uri',
'headers' => [
'Content-Type' => 'text/plain',
],
'body' => 'body'
];
/**
* {@inheritdoc}
*/
public function send($method, $uri, array $headers = [], $body = null)
{
if (in_array($method, ['GET', 'HEAD', 'TRACE'])) {
return $uri === self::$requestData['uri'] &&
$headers === self::$requestData['headers'] &&
is_null($body);
}
return in_array($method, ['POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']) &&
$uri === self::$requestData['uri'] &&
$headers === self::$requestData['headers'] &&
$body === self::$requestData['body'];
}
}