1 | <?php |
||
25 | trait ApiTestCase |
||
26 | { |
||
27 | use AssertsTrait; |
||
28 | |||
29 | /** |
||
30 | * @var SchemaManager |
||
31 | */ |
||
32 | protected static $schemaManager; |
||
33 | |||
34 | /** |
||
35 | * @var SwaggerDocument |
||
36 | */ |
||
37 | protected static $document; |
||
38 | |||
39 | /** |
||
40 | * @var ApiTestClient |
||
41 | */ |
||
42 | protected $client; |
||
43 | |||
44 | /** |
||
45 | * PHPUnit cannot add this to code coverage |
||
46 | * |
||
47 | * @codeCoverageIgnore |
||
48 | * |
||
49 | * @param string $swaggerPath |
||
50 | * |
||
51 | * @throws \InvalidArgumentException |
||
52 | * @throws \org\bovigo\vfs\vfsStreamException |
||
53 | */ |
||
54 | public static function initSchemaManager($swaggerPath) |
||
80 | |||
81 | /** |
||
82 | * Create a client, booting the kernel using SYMFONY_ENV = $this->env |
||
83 | */ |
||
84 | protected function setUp() |
||
90 | |||
91 | /** |
||
92 | * @return array |
||
93 | */ |
||
94 | protected function getDefaultServerVars() |
||
98 | |||
99 | /** |
||
100 | * @return array |
||
101 | */ |
||
102 | protected function getEnv() |
||
106 | |||
107 | /** |
||
108 | * @return bool |
||
109 | */ |
||
110 | protected function getValidateErrorResponse() |
||
114 | |||
115 | /** |
||
116 | * @param string $path |
||
117 | * @param array $params |
||
118 | * |
||
119 | * @return object |
||
120 | * @throws ApiResponseErrorException |
||
121 | */ |
||
122 | protected function get($path, array $params = []) |
||
126 | |||
127 | /** |
||
128 | * @param string $path |
||
129 | * @param array $params |
||
130 | * |
||
131 | * @return object |
||
132 | * @throws ApiResponseErrorException |
||
133 | */ |
||
134 | protected function delete($path, array $params = []) |
||
138 | |||
139 | /** |
||
140 | * @param string $path |
||
141 | * @param array $content |
||
142 | * @param array $params |
||
143 | * |
||
144 | * @return object |
||
145 | * @throws ApiResponseErrorException |
||
146 | */ |
||
147 | protected function patch($path, array $content, array $params = []) |
||
151 | |||
152 | /** |
||
153 | * @param string $path |
||
154 | * @param array $content |
||
155 | * @param array $params |
||
156 | * |
||
157 | * @return object |
||
158 | * @throws ApiResponseErrorException |
||
159 | */ |
||
160 | protected function post($path, array $content, array $params = []) |
||
164 | |||
165 | /** |
||
166 | * @param string $path |
||
167 | * @param array $content |
||
168 | * @param array $params |
||
169 | * |
||
170 | * @return object |
||
171 | * @throws ApiResponseErrorException |
||
172 | */ |
||
173 | protected function put($path, array $content, array $params = []) |
||
177 | |||
178 | /** |
||
179 | * @param string $path |
||
180 | * @param array $method |
||
181 | * @param array $params |
||
182 | * @param array|null $content |
||
183 | * |
||
184 | * @return object |
||
185 | * @throws ApiResponseErrorException |
||
186 | */ |
||
187 | protected function sendRequest($path, $method, array $params = [], array $content = null) |
||
198 | |||
199 | /** |
||
200 | * @param string $path |
||
201 | * @param array $params |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | private function assembleUri($path, array $params = []) |
||
214 | |||
215 | /** |
||
216 | * @param string $fullPath |
||
217 | * @param string $method |
||
218 | * |
||
219 | * @return object|null |
||
220 | * @throws ApiResponseErrorException |
||
221 | */ |
||
222 | private function getJsonForLastRequest($fullPath, $method) |
||
259 | |||
260 | /** |
||
261 | * @param $code |
||
262 | * @param Response $response |
||
263 | * @param string $method |
||
264 | * @param string $fullPath |
||
265 | * @param mixed $data |
||
266 | */ |
||
267 | private function validateResponse($code, $response, $method, $fullPath, $data) |
||
305 | |||
306 | /** |
||
307 | * @param mixed $expected |
||
308 | * @param mixed $actual |
||
309 | * @param string $message |
||
310 | * |
||
311 | * @return mixed |
||
312 | */ |
||
313 | public abstract function assertSame($expected, $actual, $message = ''); |
||
314 | } |
||
315 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: