1 | <?php |
||
29 | class ApiContext implements ApiContextInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var HttpClient |
||
33 | */ |
||
34 | private $client; |
||
35 | |||
36 | /** |
||
37 | * @var RequestFactory |
||
38 | */ |
||
39 | private $requestFactory; |
||
40 | |||
41 | /** |
||
42 | * @var StreamFactory |
||
43 | */ |
||
44 | private $streamFactory; |
||
45 | |||
46 | /** |
||
47 | * @var MultipartStreamBuilder|null |
||
48 | */ |
||
49 | private $multipartStreamBuilder; |
||
50 | |||
51 | /** |
||
52 | * @var FileLocatorInterface |
||
53 | */ |
||
54 | private $fileLocator; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | private $baseUrl; |
||
60 | |||
61 | /** |
||
62 | * @var string[][] |
||
63 | */ |
||
64 | private $headers = []; |
||
65 | |||
66 | /** |
||
67 | * @var RequestInterface|null |
||
68 | */ |
||
69 | private $request; |
||
70 | |||
71 | /** |
||
72 | * @var ResponseInterface|null |
||
73 | */ |
||
74 | private $response; |
||
75 | |||
76 | /** |
||
77 | * @var Matcher |
||
78 | */ |
||
79 | private $matcher; |
||
80 | |||
81 | /** |
||
82 | * @var resource[] |
||
83 | */ |
||
84 | private $resources = []; |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | public function __construct() |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function __destruct() |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function setClient(HttpClient $client) |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | public function setRequestFactory(RequestFactory $requestFactory) |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function setStreamFactory(StreamFactory $streamFactory) |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function setFileLocator(FileLocatorInterface $fileFileLocator) |
||
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | public function setBaseUrl($baseUrl) |
||
145 | |||
146 | /** |
||
147 | * @BeforeScenario |
||
148 | * |
||
149 | * @Given I reset the API context |
||
150 | */ |
||
151 | public function reset() |
||
166 | |||
167 | /** |
||
168 | * @param string $header |
||
169 | * @param string $value |
||
170 | * |
||
171 | * @Given I set the header ":header" with value ":value" |
||
172 | */ |
||
173 | public function setHeader($header, $value) |
||
177 | |||
178 | /** |
||
179 | * @param string $header |
||
180 | * @param string $value |
||
181 | * |
||
182 | * @Given I add the header ":header" with value ":value" |
||
183 | */ |
||
184 | public function addHeader($header, $value) |
||
188 | |||
189 | /** |
||
190 | * @param string $header |
||
191 | * |
||
192 | * @Given I remove the header ":header" |
||
193 | */ |
||
194 | public function removeHeader($header) |
||
198 | |||
199 | /** |
||
200 | * @param string $name |
||
201 | * @param string $value |
||
202 | * |
||
203 | * @Given I set the field ":name" with value ":value" |
||
204 | */ |
||
205 | public function setField($name, $value) |
||
209 | |||
210 | /** |
||
211 | * @param string $name |
||
212 | * @param string $file |
||
213 | * @param string|null $filename |
||
214 | * |
||
215 | * @Given I set the field ":name" with file ":file" |
||
216 | * @Given I set the field ":name" with file ":file" and filename ":filename" |
||
217 | */ |
||
218 | public function setFile($name, $file, $filename = null) |
||
224 | |||
225 | /** |
||
226 | * @param string $method |
||
227 | * @param string $url |
||
228 | * |
||
229 | * @When I send a ":method" request to ":url" |
||
230 | */ |
||
231 | public function send($method, $url) |
||
237 | |||
238 | /** |
||
239 | * @param string $method |
||
240 | * @param string $url |
||
241 | * @param PyStringNode $string |
||
242 | * |
||
243 | * @When I send a ":method" request to ":url" with body: |
||
244 | */ |
||
245 | public function sendWith($method, $url, PyStringNode $string) |
||
256 | |||
257 | /** |
||
258 | * @param string $statusCode |
||
259 | * |
||
260 | * @Then the response status code should be ":statusCode" |
||
261 | */ |
||
262 | public function assertResponseStatusCode($statusCode) |
||
266 | |||
267 | /** |
||
268 | * @param PyStringNode $json |
||
269 | * |
||
270 | * @Then the response should contain: |
||
271 | */ |
||
272 | public function assertResponseContains(PyStringNode $json) |
||
278 | |||
279 | /** |
||
280 | * @Then the response should be empty |
||
281 | */ |
||
282 | public function assertResponseEmpty() |
||
286 | |||
287 | /** |
||
288 | * @Then I print the response |
||
289 | */ |
||
290 | public function printResponse() |
||
300 | |||
301 | /** |
||
302 | * @return RequestInterface |
||
303 | */ |
||
304 | public function getRequest() |
||
312 | |||
313 | /** |
||
314 | * @return ResponseInterface |
||
315 | */ |
||
316 | public function getResponse() |
||
324 | |||
325 | /** |
||
326 | * @return MultipartStreamBuilder |
||
327 | */ |
||
328 | private function getMultipartStreamBuilder() |
||
336 | |||
337 | /** |
||
338 | * @param string $url |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | private function prepareUrl($url) |
||
346 | |||
347 | private function sendRequest() |
||
370 | } |
||
371 |