1 | <?php |
||
24 | trait GeneralTestsHelpersTrait |
||
25 | { |
||
26 | |||
27 | // ---[ HTTP CALLS ]------------------------------------------------------------------------------------------------ |
||
28 | |||
29 | /** |
||
30 | * @param $endpoint |
||
31 | * @param string $verb |
||
32 | * @param array $data |
||
33 | * @param bool $protected |
||
34 | * @param array $headers |
||
35 | * |
||
36 | * @return mixed |
||
37 | * @throws \Symfony\Component\Debug\Exception\UndefinedMethodException |
||
38 | */ |
||
39 | public function apiCall($endpoint, $verb = 'get', array $data = [], $protected = true, array $headers = []) |
||
67 | |||
68 | /** |
||
69 | * Inject the ID in the Endpoint URI |
||
70 | * |
||
71 | * Example: you give it ('users/{id}/stores', 100) it returns 'users/100/stores' |
||
72 | * |
||
73 | * @param $endpoint |
||
74 | * @param $id |
||
75 | * @param bool $skipEncoding |
||
76 | * @param string $replace |
||
77 | * |
||
78 | * @return mixed |
||
79 | */ |
||
80 | public function injectEndpointId($endpoint, $id, $skipEncoding = false, $replace = '{id}') |
||
92 | |||
93 | // ---[ RESPONSE MODIFIERS ]---------------------------------------------------------------------------------------- |
||
94 | |||
95 | /** |
||
96 | * get response object, get the string content from it and convert it to an std object |
||
97 | * making it easier to read |
||
98 | * |
||
99 | * @param $response |
||
100 | * |
||
101 | * @return mixed |
||
102 | */ |
||
103 | public function getResponseObject(Response $response) |
||
107 | |||
108 | /** |
||
109 | * @param $response |
||
110 | * |
||
111 | * @return mixed |
||
112 | */ |
||
113 | private function responseToArray($response) |
||
125 | |||
126 | /** |
||
127 | * Format the given key and value into a JSON string for expectation checks. |
||
128 | * |
||
129 | * @param string $key |
||
130 | * @param mixed $value |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | private function formatToKeyValueToString($key, $value) |
||
148 | |||
149 | // ---[ UPLOADER'S ]------------------------------------------------------------------------------------------------ |
||
150 | |||
151 | /** |
||
152 | * @param $fileName |
||
153 | * @param $stubDirPath |
||
154 | * @param string $mimeType |
||
155 | * @param null $size |
||
156 | * |
||
157 | * @return \Illuminate\Http\UploadedFile |
||
158 | */ |
||
159 | public function getTestingFile($fileName, $stubDirPath, $mimeType = 'text/plain', $size = null) |
||
165 | |||
166 | /** |
||
167 | * @param $imageName |
||
168 | * @param $stubDirPath |
||
169 | * @param string $mimeType |
||
170 | * @param null $size |
||
171 | * |
||
172 | * @return \Illuminate\Http\UploadedFile |
||
173 | */ |
||
174 | public function getTestingImage($imageName, $stubDirPath, $mimeType = 'image/jpeg', $size = null) |
||
178 | |||
179 | // ---[ CUSTOM ASSERTIONS ]----------------------------------------------------------------------------------------- |
||
180 | |||
181 | /** |
||
182 | * @param \Dingo\Api\Http\Response $response |
||
183 | * @param array $messages |
||
184 | */ |
||
185 | public function assertValidationErrorContain(DingoAPIResponse $response, array $messages) |
||
193 | |||
194 | /** |
||
195 | * @param $keys |
||
196 | * @param $response |
||
197 | */ |
||
198 | public function assertResponseContainKeys($keys, $response) |
||
208 | |||
209 | /** |
||
210 | * @param $values |
||
211 | * @param $response |
||
212 | */ |
||
213 | public function assertResponseContainValues($values, $response) |
||
223 | |||
224 | /** |
||
225 | * @param $data |
||
226 | * @param $response |
||
227 | */ |
||
228 | public function assertResponseContainKeyValue($data, $response) |
||
240 | |||
241 | // ---[ MOCKING ]--------------------------------------------------------------------------------------------------- |
||
242 | |||
243 | /** |
||
244 | * Mocking helper |
||
245 | * |
||
246 | * @param $class |
||
247 | * |
||
248 | * @return \Mockery\MockInterface |
||
249 | */ |
||
250 | public function mock($class) |
||
257 | |||
258 | } |
||
259 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.