1+ <?php
2+
3+ namespace EnricoStahn \JsonAssert \Integration ;
4+
5+ use EnricoStahn \JsonAssert \Assert ;
6+ use Symfony \Component \HttpFoundation \Response ;
7+
8+ trait Symfony
9+ {
10+ /**
11+ * Asserts that json content is valid according to the provided schema file.
12+ *
13+ * Example:
14+ *
15+ * static::assertJsonMatchesSchema(json_decode('{"foo":1}'), './schema.json')
16+ *
17+ * @param string $schema Path to the schema file
18+ * @param Response $response JSON array or object
19+ */
20+ public static function assertJsonMatchesSchema ($ schema , Response $ response )
21+ {
22+ Assert::assertJsonMatchesSchema ($ schema , json_decode ($ response ->getContent ()));
23+ }
24+
25+ /**
26+ * Asserts that json content is valid according to the provided schema string.
27+ *
28+ * @param string $schema Schema data
29+ * @param Response $response JSON content
30+ */
31+ public static function assertJsonMatchesSchemaString ($ schema , Response $ response )
32+ {
33+ Assert::assertJsonMatchesSchemaString ($ schema , json_decode ($ response ->getContent ()));
34+ }
35+
36+ /**
37+ * Asserts if the value retrieved with the expression equals the expected value.
38+ *
39+ * Example:
40+ *
41+ * static::assertJsonValueEquals(33, 'foo.bar[0]', $json);
42+ *
43+ * @param mixed $expected Expected value
44+ * @param string $expression Expression to retrieve the result
45+ * (e.g. locations[?state == 'WA'].name | sort(@))
46+ * @param Response $response JSON Content
47+ */
48+ public static function assertJsonValueEquals ($ expected , $ expression , $ response )
49+ {
50+ Assert::assertJsonValueEquals ($ expected , $ expression , json_decode ($ response ->getContent ()));
51+ }
52+ }
0 commit comments