@@ -20,11 +20,13 @@ JSON assertions for PHPUnit includes traits/methods to help validate your JSON d
20
20
21
21
or in your ` composer.json ` :
22
22
23
- {
24
- "require-dev": {
25
- "estahn/phpunit-json-assertions ": "@stable"
26
- }
23
+ ``` json
24
+ {
25
+ "require-dev " : {
26
+ "estahn/phpunit-json-assertions" : " @stable "
27
27
}
28
+ }
29
+ ```
28
30
29
31
## Asserts
30
32
@@ -40,70 +42,74 @@ You can either use the `trait` or `class` version.
40
42
41
43
### Trait
42
44
43
- <?php
44
-
45
- namespace EnricoStahn\JsonAssert\Tests;
46
-
47
- use EnricoStahn\JsonAssert\Assert as JsonAssert;
45
+ ``` php
46
+ <?php
47
+
48
+ namespace EnricoStahn\JsonAssert\Tests;
49
+
50
+ use EnricoStahn\JsonAssert\Assert as JsonAssert;
51
+
52
+ class MyTestCase extends \PHPUnit_Framework_TestCase
53
+ {
54
+ use JsonAssert;
48
55
49
- class MyTestCase extends \PHPUnit_Framework_TestCase
56
+ public function testJsonDocumentIsValid()
50
57
{
51
- use JsonAssert;
52
-
53
- public function testJsonDocumentIsValid()
54
- {
55
- // my-schema.json
56
- //
57
- // {
58
- // "type" : "object",
59
- // "properties" : {
60
- // "foo" : {
61
- // "type" : "integer"
62
- // }
63
- // },
64
- // "required" : [ "foo" ]
65
- // }
58
+ // my-schema.json
59
+ //
60
+ // {
61
+ // "type" : "object",
62
+ // "properties" : {
63
+ // "foo" : {
64
+ // "type" : "integer"
65
+ // }
66
+ // },
67
+ // "required" : [ "foo" ]
68
+ // }
69
+
70
+ $json = json_decode('{"foo":1}');
66
71
67
- $json = json_decode('{"foo":1}');
68
-
69
- $this->assertJsonMatchesSchemaString('./my-schema.json', $json);
70
- $this->assertJsonValueEquals(1, '* | [0]', $json);
71
- }
72
+ $this->assertJsonMatchesSchemaString('./my-schema.json', $json);
73
+ $this->assertJsonValueEquals(1, '* | [0]', $json);
72
74
}
75
+ }
76
+ ```
73
77
74
78
### Class
75
79
76
80
In case you don't want to use the ` trait ` you can use the provided class wich extends from ` \PHPUnit_Framework_TestCase ` .
77
81
You can either extend your test case or use the static methods like below.
78
82
79
- <?php
80
-
81
- namespace EnricoStahn\JsonAssert\Tests;
82
-
83
- use EnricoStahn\JsonAssert\AssertClass as JsonAssert;
84
-
85
- class MyTestCase extends \PHPUnit_Framework_TestCase
83
+ ``` php
84
+ <?php
85
+
86
+ namespace EnricoStahn\JsonAssert\Tests;
87
+
88
+ use EnricoStahn\JsonAssert\AssertClass as JsonAssert;
89
+
90
+ class MyTestCase extends \PHPUnit_Framework_TestCase
91
+ {
92
+ public function testJsonDocumentIsValid()
86
93
{
87
- public function testJsonDocumentIsValid()
88
- {
89
- // my-schema.json
90
- //
91
- // {
92
- // "type " : "object",
93
- // "properties " : {
94
- // "foo" : {
95
- // "type" : "integer"
96
- // }
97
- // },
98
- // "required" : [ "foo" ]
99
- // }
94
+ // my-schema.json
95
+ //
96
+ // {
97
+ // "type" : "object",
98
+ // "properties" : {
99
+ // "foo " : {
100
+ // "type " : "integer"
101
+ // }
102
+ // },
103
+ // "required" : [ "foo" ]
104
+ // }
105
+
106
+ $json = json_decode('{"foo":1}');
100
107
101
- $json = json_decode('{"foo":1}');
102
-
103
- JsonAssert::assertJsonMatchesSchemaString('./my-schema.json', $json);
104
- JsonAssert::assertJsonValueEquals(1, '* | [0]', $json);
105
- }
108
+ JsonAssert::assertJsonMatchesSchemaString('./my-schema.json', $json);
109
+ JsonAssert::assertJsonValueEquals(1, '* | [0]', $json);
106
110
}
111
+ }
112
+ ```
107
113
108
114
## Tests
109
115
0 commit comments