1 | <?php |
||
7 | trait AssertJsonResponse |
||
8 | { |
||
9 | use AssertArrays, MakesHttpRequests; |
||
10 | |||
11 | /** |
||
12 | * Assert that the JSON response has exactly the given structure. |
||
13 | * |
||
14 | * @param array $structure |
||
15 | * @param array|null $responseData |
||
16 | * |
||
17 | * @return $this |
||
18 | */ |
||
19 | 1 | public function seeJsonStructureEquals(array $structure, $responseData = null) |
|
27 | |||
28 | /** |
||
29 | * Assert that the JSON response has a given typed structure. |
||
30 | * |
||
31 | * @param array|null $structure |
||
32 | * @param array|null $responseData |
||
33 | * @return $this |
||
34 | */ |
||
35 | 1 | public function seeJsonTypedStructure(array $structure = null, $responseData = null) |
|
63 | |||
64 | /** |
||
65 | * Return the json response or a part of it as an array. |
||
66 | * |
||
67 | * @param string $key |
||
68 | * |
||
69 | * @return mixed |
||
70 | */ |
||
71 | 1 | public function jsonResponse($key = null) |
|
77 | |||
78 | 2 | public function decodeResponseJson() |
|
88 | } |
||
89 |
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.