16
16
use JsonSchema \Validator ;
17
17
18
18
/**
19
- * Asserts to validate JSON data
19
+ * Asserts to validate JSON data.
20
20
*
21
21
* - All assert methods expect deserialised JSON data (an actual object or array)
22
22
* since the deserialisation method should be up to the user.
25
25
trait Assert
26
26
{
27
27
/**
28
- * Asserts that json content is valid according to the provided schema file
28
+ * Asserts that json content is valid according to the provided schema file.
29
29
*
30
30
* Example:
31
31
*
@@ -37,10 +37,10 @@ trait Assert
37
37
public static function assertJsonMatchesSchema ($ schema , $ content )
38
38
{
39
39
$ retriever = new UriRetriever ();
40
- $ schema = $ retriever ->retrieve ('file:// ' . realpath ($ schema ));
40
+ $ schema = $ retriever ->retrieve ('file:// ' . realpath ($ schema ));
41
41
42
42
$ refResolver = new RefResolver ($ retriever );
43
- $ refResolver ->resolve ($ schema , 'file:// ' . __DIR__ . '/../Resources/schemas/ ' );
43
+ $ refResolver ->resolve ($ schema , 'file:// ' . __DIR__ . '/../Resources/schemas/ ' );
44
44
45
45
$ validator = new Validator ();
46
46
$ validator ->check ($ content , $ schema );
@@ -49,13 +49,13 @@ public static function assertJsonMatchesSchema($schema, $content)
49
49
$ messages = array_map (function ($ e ) use ($ message ) {
50
50
return sprintf ($ message , $ e ['property ' ], $ e ['constraint ' ], $ e ['message ' ]);
51
51
}, $ validator ->getErrors ());
52
- $ messages [] = '- Response: ' . json_encode ($ content );
52
+ $ messages [] = '- Response: ' . json_encode ($ content );
53
53
54
54
self ::assertTrue ($ validator ->isValid (), implode ("\n" , $ messages ));
55
55
}
56
56
57
57
/**
58
- * Asserts that json content is valid according to the provided schema string
58
+ * Asserts that json content is valid according to the provided schema string.
59
59
*
60
60
* @param string $schema Schema data
61
61
* @param array|object $content JSON content
@@ -69,7 +69,7 @@ public static function assertJsonMatchesSchemaString($schema, $content)
69
69
}
70
70
71
71
/**
72
- * Asserts if the value retrieved with the expression equals the expected value
72
+ * Asserts if the value retrieved with the expression equals the expected value.
73
73
*
74
74
* Example:
75
75
*
@@ -90,6 +90,7 @@ public static function assertJsonValueEquals($expected, $expression, $json)
90
90
/**
91
91
* @param $expression
92
92
* @param $data
93
+ *
93
94
* @return mixed|null
94
95
*/
95
96
public static function search ($ expression , $ data )
@@ -98,13 +99,14 @@ public static function search($expression, $data)
98
99
}
99
100
100
101
/**
101
- * Helper method to deserialise a JSON string into an object
102
+ * Helper method to deserialise a JSON string into an object.
102
103
*
103
104
* @param mixed $data The JSON string
105
+ *
104
106
* @return array|object
105
107
*/
106
108
public static function getJsonObject ($ data )
107
109
{
108
110
return (is_array ($ data ) || is_object ($ data )) ? $ data : json_decode ($ data );
109
111
}
110
- }
112
+ }
0 commit comments