1 | <?php |
||
28 | class ApiContext implements ApiContextInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var HttpClient |
||
32 | */ |
||
33 | private $client; |
||
34 | |||
35 | /** |
||
36 | * @var RequestFactory |
||
37 | */ |
||
38 | private $requestFactory; |
||
39 | |||
40 | /** |
||
41 | * @var StreamFactory |
||
42 | */ |
||
43 | private $streamFactory; |
||
44 | |||
45 | /** |
||
46 | * @var MultipartStreamBuilder|null |
||
47 | */ |
||
48 | private $multipartStreamBuilder; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | private $baseUrl; |
||
54 | |||
55 | /** |
||
56 | * @var string[][] |
||
57 | */ |
||
58 | private $headers = []; |
||
59 | |||
60 | /** |
||
61 | * @var RequestInterface|null |
||
62 | */ |
||
63 | private $request; |
||
64 | |||
65 | /** |
||
66 | * @var ResponseInterface|null |
||
67 | */ |
||
68 | private $response; |
||
69 | |||
70 | /** |
||
71 | * @var Matcher |
||
72 | */ |
||
73 | private $matcher; |
||
74 | |||
75 | public function __construct() |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public function setClient(HttpClient $client) |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function setRequestFactory(RequestFactory $requestFactory) |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function setStreamFactory(StreamFactory $streamFactory) |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function setBaseUrl($baseUrl) |
||
115 | |||
116 | /** |
||
117 | * @BeforeScenario |
||
118 | */ |
||
119 | public function reset() |
||
126 | |||
127 | /** |
||
128 | * @param string $header |
||
129 | * @param string $value |
||
130 | * |
||
131 | * @Given I set the header ":header" with value ":value" |
||
132 | */ |
||
133 | public function setHeader($header, $value) |
||
137 | |||
138 | /** |
||
139 | * @param string $header |
||
140 | * @param string $value |
||
141 | * |
||
142 | * @Given I add the header ":header" with value ":value" |
||
143 | */ |
||
144 | public function addHeader($header, $value) |
||
148 | |||
149 | /** |
||
150 | * @param string $header |
||
151 | * |
||
152 | * @Given I remove the header ":header" |
||
153 | */ |
||
154 | public function removeHeader($header) |
||
158 | |||
159 | /** |
||
160 | * @param string $name |
||
161 | * @param string $value |
||
162 | * |
||
163 | * @Given I set the field ":name" with value ":value" |
||
164 | */ |
||
165 | public function setField($name, $value) |
||
169 | |||
170 | /** |
||
171 | * @param string $method |
||
172 | * @param string $url |
||
173 | * |
||
174 | * @When I send a ":method" request to ":url" |
||
175 | */ |
||
176 | public function send($method, $url) |
||
182 | |||
183 | /** |
||
184 | * @param string $method |
||
185 | * @param string $url |
||
186 | * @param PyStringNode $string |
||
187 | * |
||
188 | * @When I send a ":method" request to ":url" with body: |
||
189 | */ |
||
190 | public function sendWith($method, $url, PyStringNode $string) |
||
201 | |||
202 | /** |
||
203 | * @param string $statusCode |
||
204 | * |
||
205 | * @Then the response status code should be ":statusCode" |
||
206 | */ |
||
207 | public function assertResponseStatusCode($statusCode) |
||
211 | |||
212 | /** |
||
213 | * @param PyStringNode $json |
||
214 | * |
||
215 | * @Then the response should contain: |
||
216 | */ |
||
217 | public function assertResponseContains(PyStringNode $json) |
||
223 | |||
224 | /** |
||
225 | * @Then the response should be empty |
||
226 | */ |
||
227 | public function assertResponseEmpty() |
||
231 | |||
232 | /** |
||
233 | * @Then I print the response |
||
234 | */ |
||
235 | public function printResponse() |
||
245 | |||
246 | /** |
||
247 | * @return RequestInterface |
||
248 | */ |
||
249 | public function getRequest() |
||
257 | |||
258 | /** |
||
259 | * @return ResponseInterface |
||
260 | */ |
||
261 | public function getResponse() |
||
269 | |||
270 | /** |
||
271 | * @return MultipartStreamBuilder |
||
272 | */ |
||
273 | private function getMultipartStreamBuilder() |
||
281 | |||
282 | /** |
||
283 | * @param string $url |
||
284 | * |
||
285 | * @return string |
||
286 | */ |
||
287 | private function prepareUrl($url) |
||
291 | |||
292 | private function sendRequest() |
||
310 | } |
||
311 |