1 | <?php |
||
26 | trait Assert |
||
27 | { |
||
28 | /** |
||
29 | * @var SchemaStorage |
||
30 | */ |
||
31 | private static $schemaStorage = null; |
||
32 | |||
33 | /** |
||
34 | * Asserts that json content is valid according to the provided schema file. |
||
35 | * |
||
36 | * Example: |
||
37 | * |
||
38 | 9 | * static::assertJsonMatchesSchema(json_decode('{"foo":1}'), './schema.json') |
|
39 | * |
||
40 | * @param string|null $schema Path to the schema file |
||
41 | * @param array|object $content JSON array or object |
||
42 | 9 | */ |
|
43 | 9 | public static function assertJsonMatchesSchema($content, $schema = null) |
|
71 | |||
72 | /** |
||
73 | * Asserts that json content is valid according to the provided schema file. |
||
74 | * |
||
75 | * Example: |
||
76 | * |
||
77 | * static::assertJsonMatchesSchema(json_decode('{"foo":1}'), './schema.json') |
||
78 | * |
||
79 | * @param string|null $schema Path to the schema file |
||
80 | * @param array|object $content JSON array or object |
||
81 | * |
||
82 | * @deprecated This will be removed in the next major version (4.x). |
||
83 | 4 | */ |
|
84 | public static function assertJsonMatchesSchemaDepr($schema, $content) |
||
88 | 3 | ||
89 | 3 | /** |
|
90 | * Asserts that json content is valid according to the provided schema string. |
||
91 | * |
||
92 | * @param string $schema Schema data |
||
93 | * @param array|object $content JSON content |
||
94 | */ |
||
95 | public static function assertJsonMatchesSchemaString($schema, $content) |
||
102 | |||
103 | /** |
||
104 | * Asserts if the value retrieved with the expression equals the expected value. |
||
105 | * |
||
106 | * Example: |
||
107 | * |
||
108 | * static::assertJsonValueEquals(33, 'foo.bar[0]', $json); |
||
109 | * |
||
110 | * @param mixed $expected Expected value |
||
111 | * @param string $expression Expression to retrieve the result |
||
112 | * (e.g. locations[?state == 'WA'].name | sort(@)) |
||
113 | * @param array|object $json JSON Content |
||
114 | */ |
||
115 | public static function assertJsonValueEquals($expected, $expression, $json) |
||
122 | |||
123 | /** |
||
124 | * Helper method to deserialise a JSON string into an object. |
||
125 | * |
||
126 | * @param mixed $data The JSON string |
||
127 | * |
||
128 | * @return array|object |
||
129 | */ |
||
130 | public static function getJsonObject($data) |
||
134 | } |
||
135 |