1 | <?php |
||
14 | class RestApiContext implements Context, SnippetAcceptingContext |
||
15 | { |
||
16 | private $asserter; |
||
17 | |||
18 | private $restApiBrowser; |
||
19 | |||
20 | public function __construct(RestApiBrowser $restApiBrowser) |
||
21 | { |
||
22 | $this->restApiBrowser = $restApiBrowser; |
||
23 | $this->asserter = new asserter\generator; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @param string $method request method |
||
28 | * @param string $url relative url |
||
29 | * |
||
30 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)"$/ |
||
31 | */ |
||
32 | public function iSendARequest($method, $url) |
||
33 | { |
||
34 | $this->restApiBrowser->sendRequest($method, $url); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Sends HTTP request to specific URL with raw body from PyString. |
||
39 | * |
||
40 | * @param string $method request method |
||
41 | * @param string $url relative url |
||
42 | * @param PyStringNode $body |
||
43 | * |
||
44 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)" with body:$/ |
||
45 | */ |
||
46 | public function iSendARequestWithBody($method, $url, PyStringNode $body) |
||
50 | |||
51 | /** |
||
52 | * @param string $code status code |
||
53 | * |
||
54 | * @Then /^(?:the )?response status code should be (\d+)$/ |
||
55 | */ |
||
56 | public function theResponseCodeShouldBe($code) |
||
62 | |||
63 | /** |
||
64 | * @return ResponseInterface |
||
65 | */ |
||
66 | private function getResponse() |
||
70 | |||
71 | /** |
||
72 | * @Given /^I set "([^"]*)" header equal to "([^"]*)"$/ |
||
73 | */ |
||
74 | public function iSetHeaderEqualTo($headerName, $headerValue) |
||
78 | |||
79 | /** |
||
80 | * @Given /^I add "([^"]*)" header equal to "([^"]*)"$/ |
||
81 | */ |
||
82 | public function iAddHeaderEqualTo($headerName, $headerValue) |
||
86 | |||
87 | /** |
||
88 | * Set login / password for next HTTP authentication |
||
89 | * |
||
90 | * @When /^I set basic authentication with "(?P<username>[^"]*)" and "(?P<password>[^"]*)"$/ |
||
91 | */ |
||
92 | public function iSetBasicAuthenticationWithAnd($username, $password) |
||
97 | |||
98 | /** |
||
99 | * @Then print request and response |
||
100 | */ |
||
101 | public function printRequestAndResponse() |
||
108 | |||
109 | /** |
||
110 | * @Then print request |
||
111 | */ |
||
112 | public function printRequest() |
||
123 | |||
124 | /** |
||
125 | * @return RequestInterface |
||
126 | */ |
||
127 | private function getRequest() |
||
131 | |||
132 | /** |
||
133 | * @param array $headers |
||
134 | * @return string |
||
135 | */ |
||
136 | private function getRawHeaders(array $headers) |
||
146 | |||
147 | /** |
||
148 | * @Then print response |
||
149 | */ |
||
150 | public function printResponse() |
||
165 | } |
||
166 |