1 | <?php |
||
17 | trait TestsResponseHelperTrait |
||
18 | { |
||
19 | /** |
||
20 | * get response object, get the string content from it and convert it to an std object |
||
21 | * making it easier to read |
||
22 | * |
||
23 | * @param $httpResponse |
||
24 | * |
||
25 | * @return mixed |
||
26 | */ |
||
27 | public function getResponseObject(Response $httpResponse) |
||
31 | |||
32 | /** |
||
33 | * @param $httpResponse |
||
34 | * |
||
35 | * @return mixed |
||
36 | */ |
||
37 | private function responseToArray($httpResponse) |
||
49 | |||
50 | /** |
||
51 | * @param \Dingo\Api\Http\Response $httpResponse |
||
52 | * @param array $messages |
||
53 | */ |
||
54 | public function assertValidationErrorContain(DingoAPIResponse $httpResponse, array $messages) |
||
62 | |||
63 | /** |
||
64 | * @param $keys |
||
65 | * @param $httpResponse |
||
66 | */ |
||
67 | public function assertResponseContainKeys($keys, $httpResponse) |
||
77 | |||
78 | /** |
||
79 | * @param $values |
||
80 | * @param $httpResponse |
||
81 | */ |
||
82 | public function assertResponseContainValues($values, $httpResponse) |
||
92 | |||
93 | /** |
||
94 | * @param $data |
||
95 | * @param $httpResponse |
||
96 | */ |
||
97 | public function assertResponseContainKeyValue($data, $httpResponse) |
||
109 | |||
110 | /** |
||
111 | * Format the given key and value into a JSON string for expectation checks. |
||
112 | * |
||
113 | * @param string $key |
||
114 | * @param mixed $value |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | private function formatToKeyValueToString($key, $value) |
||
132 | |||
133 | } |
||
134 |
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.