1 | <?php |
||
21 | trait ApiTestCase |
||
22 | { |
||
23 | use AssertsTrait; |
||
24 | |||
25 | /** |
||
26 | * @var SchemaManager |
||
27 | */ |
||
28 | protected static $schemaManager; |
||
29 | |||
30 | /** |
||
31 | * @var SwaggerDocument |
||
32 | */ |
||
33 | protected static $document; |
||
34 | |||
35 | /** |
||
36 | * @var ApiTestClient |
||
37 | */ |
||
38 | protected $client; |
||
39 | |||
40 | /** |
||
41 | * PHPUnit cannot add this to code coverage |
||
42 | * |
||
43 | * @codeCoverageIgnore |
||
44 | * |
||
45 | * @param $swaggerPath |
||
46 | * |
||
47 | * @throws \InvalidArgumentException |
||
48 | * @throws \org\bovigo\vfs\vfsStreamException |
||
49 | */ |
||
50 | public static function initSchemaManager($swaggerPath) |
||
76 | |||
77 | /** |
||
78 | * Create a client, booting the kernel using SYMFONY_ENV = $this->env |
||
79 | */ |
||
80 | protected function setUp() |
||
86 | |||
87 | /** |
||
88 | * Creates a Client. |
||
89 | * |
||
90 | * @param array $options An array of options to pass to the createKernel class |
||
91 | * @param array $server An array of server parameters |
||
92 | * |
||
93 | * @return Client A Client instance |
||
94 | */ |
||
95 | protected static function createClient(array $options = array(), array $server = array()) |
||
104 | |||
105 | |||
106 | /** |
||
107 | * @param string $path |
||
108 | * @param array $params |
||
109 | * |
||
110 | * @return \stdClass |
||
111 | * @throws ApiResponseErrorException |
||
112 | */ |
||
113 | protected function get($path, array $params = []) |
||
117 | |||
118 | /** |
||
119 | * @param string $path |
||
120 | * @param array $params |
||
121 | * |
||
122 | * @return \stdClass |
||
123 | * @throws ApiResponseErrorException |
||
124 | */ |
||
125 | protected function delete($path, array $params = []) |
||
129 | |||
130 | /** |
||
131 | * @param string $path |
||
132 | * @param array $content |
||
133 | * @param array $params |
||
134 | * |
||
135 | * @return \stdClass |
||
136 | * @throws ApiResponseErrorException |
||
137 | */ |
||
138 | protected function patch($path, array $content, array $params = []) |
||
142 | |||
143 | /** |
||
144 | * @param string $path |
||
145 | * @param array $content |
||
146 | * @param array $params |
||
147 | * |
||
148 | * @return \stdClass |
||
149 | * @throws ApiResponseErrorException |
||
150 | */ |
||
151 | protected function post($path, array $content, array $params = []) |
||
155 | |||
156 | /** |
||
157 | * @param string $path |
||
158 | * @param array $content |
||
159 | * @param array $params |
||
160 | * |
||
161 | * @return \stdClass |
||
162 | * @throws ApiResponseErrorException |
||
163 | */ |
||
164 | protected function put($path, array $content, array $params = []) |
||
168 | |||
169 | /** |
||
170 | * @param string $path |
||
171 | * @param array $method |
||
172 | * @param array $params |
||
173 | * @param array|null $content |
||
174 | * |
||
175 | * @return \stdClass |
||
176 | * @throws ApiResponseErrorException |
||
177 | */ |
||
178 | protected function sendRequest($path, $method, array $params = [], array $content = null) |
||
190 | |||
191 | |||
192 | /** |
||
193 | * @param string $path |
||
194 | * @param array $params |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | private function assembleUri($path, array $params = []) |
||
207 | |||
208 | /** |
||
209 | * @param string $fullPath |
||
210 | * @param string $method |
||
211 | * |
||
212 | * @return \stdClass|null |
||
213 | * @throws ApiResponseErrorException |
||
214 | */ |
||
215 | private function getJsonForLastRequest($fullPath, $method) |
||
252 | |||
253 | /** |
||
254 | * @param $code |
||
255 | * @param Response $response |
||
256 | * @param string $method |
||
257 | * @param string $fullPath |
||
258 | * @param mixed $data |
||
259 | */ |
||
260 | private function validateResponse($code, $response, $method, $fullPath, $data) |
||
287 | } |
||
288 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.