1 | <?php |
||
17 | trait Symfony |
||
18 | { |
||
19 | /** |
||
20 | * Asserts that json content is valid according to the provided schema file. |
||
21 | * |
||
22 | * Example: |
||
23 | * |
||
24 | * static::assertJsonMatchesSchema(json_decode('{"foo":1}'), './schema.json') |
||
25 | * |
||
26 | * @param string $schema Path to the schema file |
||
27 | * @param Response $response JSON array or object |
||
28 | */ |
||
29 | 1 | public static function assertJsonMatchesSchema($schema, Response $response) |
|
30 | { |
||
31 | 1 | Assert::assertJsonMatchesSchema($schema, json_decode($response->getContent())); |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Asserts that json content is valid according to the provided schema string. |
||
36 | * |
||
37 | * @param string $schema Schema data |
||
38 | * @param Response $response JSON content |
||
39 | */ |
||
40 | 1 | public static function assertJsonMatchesSchemaString($schema, Response $response) |
|
41 | { |
||
42 | 1 | Assert::assertJsonMatchesSchemaString($schema, json_decode($response->getContent())); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Asserts if the value retrieved with the expression equals the expected value. |
||
47 | * |
||
48 | * Example: |
||
49 | * |
||
50 | * static::assertJsonValueEquals(33, 'foo.bar[0]', $json); |
||
51 | * |
||
52 | * @param mixed $expected Expected value |
||
53 | * @param string $expression Expression to retrieve the result |
||
54 | * (e.g. locations[?state == 'WA'].name | sort(@)) |
||
55 | * @param Response $response JSON Content |
||
56 | */ |
||
57 | 1 | public static function assertJsonValueEquals($expected, $expression, $response) |
|
61 | |||
62 | /** |
||
63 | * Asserts that a response is successful and of type json. |
||
64 | * |
||
65 | * @param Response $response Response object |
||
66 | * @param int $statusCode Expected status code (default 200) |
||
67 | * |
||
68 | * @see \Bazinga\Bundle\RestExtraBundle\Test\WebTestCase::assertJsonResponse() |
||
69 | */ |
||
70 | 1 | public static function assertJsonResponse(Response $response, $statusCode = 200) |
|
82 | } |
||
83 |