1616use JsonSchema \Validator ;
1717
1818/**
19- * Asserts to validate JSON data
19+ * Asserts to validate JSON data.
2020 *
2121 * - All assert methods expect deserialised JSON data (an actual object or array)
2222 * since the deserialisation method should be up to the user.
2525trait Assert
2626{
2727 /**
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.
2929 *
3030 * Example:
3131 *
@@ -37,10 +37,10 @@ trait Assert
3737 public static function assertJsonMatchesSchema ($ schema , $ content )
3838 {
3939 $ retriever = new UriRetriever ();
40- $ schema = $ retriever ->retrieve ('file:// ' . realpath ($ schema ));
40+ $ schema = $ retriever ->retrieve ('file:// ' . realpath ($ schema ));
4141
4242 $ refResolver = new RefResolver ($ retriever );
43- $ refResolver ->resolve ($ schema , 'file:// ' . __DIR__ . '/../Resources/schemas/ ' );
43+ $ refResolver ->resolve ($ schema , 'file:// ' . __DIR__ . '/../Resources/schemas/ ' );
4444
4545 $ validator = new Validator ();
4646 $ validator ->check ($ content , $ schema );
@@ -49,13 +49,13 @@ public static function assertJsonMatchesSchema($schema, $content)
4949 $ messages = array_map (function ($ e ) use ($ message ) {
5050 return sprintf ($ message , $ e ['property ' ], $ e ['constraint ' ], $ e ['message ' ]);
5151 }, $ validator ->getErrors ());
52- $ messages [] = '- Response: ' . json_encode ($ content );
52+ $ messages [] = '- Response: ' . json_encode ($ content );
5353
5454 self ::assertTrue ($ validator ->isValid (), implode ("\n" , $ messages ));
5555 }
5656
5757 /**
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.
5959 *
6060 * @param string $schema Schema data
6161 * @param array|object $content JSON content
@@ -69,7 +69,7 @@ public static function assertJsonMatchesSchemaString($schema, $content)
6969 }
7070
7171 /**
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.
7373 *
7474 * Example:
7575 *
@@ -90,6 +90,7 @@ public static function assertJsonValueEquals($expected, $expression, $json)
9090 /**
9191 * @param $expression
9292 * @param $data
93+ *
9394 * @return mixed|null
9495 */
9596 public static function search ($ expression , $ data )
@@ -98,13 +99,14 @@ public static function search($expression, $data)
9899 }
99100
100101 /**
101- * Helper method to deserialise a JSON string into an object
102+ * Helper method to deserialise a JSON string into an object.
102103 *
103104 * @param mixed $data The JSON string
105+ *
104106 * @return array|object
105107 */
106108 public static function getJsonObject ($ data )
107109 {
108110 return (is_array ($ data ) || is_object ($ data )) ? $ data : json_decode ($ data );
109111 }
110- }
112+ }
0 commit comments