3
3
4
4
use JsonMatcher \Matcher \ArrayMatcher ;
5
5
use JsonMatcher \Matcher \ChainMatcher ;
6
+ use JsonMatcher \Matcher \JsonMatcher ;
6
7
use JsonMatcher \Matcher \ScalarMatcher ;
7
8
use JsonMatcher \Matcher \TypeMatcher ;
8
9
use JsonMatcher \Matcher \WildcardMatcher ;
@@ -21,9 +22,13 @@ public function setUp()
21
22
new ScalarMatcher (),
22
23
new WildcardMatcher ()
23
24
));
25
+
26
+ $ arrayMatcher = new ArrayMatcher ($ scalarMatchers );
27
+
24
28
$ this ->matcher = new Matcher (new ChainMatcher (array (
25
29
$ scalarMatchers ,
26
- new ArrayMatcher ($ scalarMatchers )
30
+ $ arrayMatcher ,
31
+ new JsonMatcher ($ arrayMatcher )
27
32
)));
28
33
29
34
$ this ->arrayValue = array (
@@ -82,4 +87,53 @@ public function test_matcher_with_scalar_values()
82
87
'@double@ '
83
88
));
84
89
}
90
+
91
+ public function test_matcher_with_json ()
92
+ {
93
+ $ json = '
94
+ {
95
+ "users":[
96
+ {
97
+ "id": 131,
98
+ "firstName": "Norbert",
99
+ "lastName": "Orzechowicz",
100
+ "enabled": true,
101
+ "roles": ["ROLE_DEVELOPER"]
102
+ },
103
+ {
104
+ "id": 132,
105
+ "firstName": "Michał",
106
+ "lastName": "Dąbrowski",
107
+ "enabled": false,
108
+ "roles": ["ROLE_DEVELOPER"]
109
+ }
110
+ ],
111
+ "prevPage": "http:\/\/example.com\/api\/users\/1?limit=2",
112
+ "nextPage": "http:\/\/example.com\/api\/users\/3?limit=2"
113
+ } ' ;
114
+ $ jsonPattern = '
115
+ {
116
+ "users":[
117
+ {
118
+ "id": "@integer@",
119
+ "firstName":"Norbert",
120
+ "lastName":"Orzechowicz",
121
+ "enabled": "@boolean@",
122
+ "roles": "@array@"
123
+ },
124
+ {
125
+ "id": "@integer@",
126
+ "firstName": "Michał",
127
+ "lastName": "Dąbrowski",
128
+ "enabled": "@boolean@",
129
+ "roles": "@array@"
130
+ }
131
+ ],
132
+ "prevPage": "@string@",
133
+ "nextPage": "@string@"
134
+ } ' ;
135
+
136
+
137
+ $ this ->assertTrue ($ this ->matcher ->match ($ json , $ jsonPattern ));
138
+ }
85
139
}
0 commit comments