Skip to content

Commit 5579bf6

Browse files
committed
Add integration for symfony HttpFoundation component
1 parent e46f40a commit 5579bf6

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "~4.8|~5.2",
22-
"codacy/coverage": "dev-master"
22+
"codacy/coverage": "dev-master",
23+
"symfony/http-foundation": "^3.0"
2324
},
2425
"autoload": {
2526
"psr-4": {

src/Integration/Symfony.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)