4
4
5
5
use Coduo \PHPMatcher \Factory \SimpleFactory ;
6
6
use Coduo \PHPMatcher \Matcher ;
7
- use Coduo \PHPMatcher \Parser ;
8
7
use Coduo \PHPMatcher \PHPMatcher ;
9
8
10
9
class MatcherTest extends \PHPUnit \Framework \TestCase
@@ -28,14 +27,14 @@ public function test_matcher_with_array_value()
28
27
'id ' => 1 ,
29
28
'firstName ' => 'Norbert ' ,
30
29
'lastName ' => 'Orzechowicz ' ,
31
- 'enabled ' => true
30
+ 'enabled ' => true ,
32
31
),
33
32
array (
34
33
'id ' => 2 ,
35
34
'firstName ' => 'Michał ' ,
36
35
'lastName ' => 'Dąbrowski ' ,
37
36
'enabled ' => true ,
38
- )
37
+ ),
39
38
),
40
39
'readyToUse ' => true ,
41
40
'data ' => new \stdClass (),
@@ -47,14 +46,14 @@ public function test_matcher_with_array_value()
47
46
'id ' => '@integer@ ' ,
48
47
'firstName ' => '@string@ ' ,
49
48
'lastName ' => 'Orzechowicz ' ,
50
- 'enabled ' => '@boolean@ '
49
+ 'enabled ' => '@boolean@ ' ,
51
50
),
52
51
array (
53
52
'id ' => '@integer@ ' ,
54
53
'firstName ' => '@string@ ' ,
55
54
'lastName ' => 'Dąbrowski ' ,
56
55
'enabled ' => '@boolean@ ' ,
57
- )
56
+ ),
58
57
),
59
58
'readyToUse ' => true ,
60
59
'data ' => '@wildcard@ ' ,
@@ -73,55 +72,112 @@ public function test_matcher_with_scalar_values($value, $pattern)
73
72
$ this ->assertTrue (PHPMatcher::match ($ value , $ pattern ));
74
73
}
75
74
76
- public function test_matcher_with_json ()
75
+ /**
76
+ * @dataProvider jsonDataProvider
77
+ */
78
+ public function test_matcher_with_json ($ json , $ jsonPattern )
77
79
{
78
- $ json = '
79
- {
80
- "users":[
81
- {
82
- "id": 131,
83
- "firstName": "Norbert",
84
- "lastName": "Orzechowicz",
85
- "enabled": true,
86
- "roles": ["ROLE_DEVELOPER"]
87
- },
88
- {
89
- "id": 132,
90
- "firstName": "Michał",
91
- "lastName": "Dąbrowski",
92
- "enabled": false,
93
- "roles": ["ROLE_DEVELOPER"]
94
- }
95
- ],
96
- "prevPage": "http:\/\/example.com\/api\/users\/1?limit=2",
97
- "nextPage": "http:\/\/example.com\/api\/users\/3?limit=2"
98
- } ' ;
99
- $ jsonPattern = '
100
- {
101
- "users":[
102
- {
103
- "id": "@integer@",
104
- "firstName":"Norbert",
105
- "lastName":"Orzechowicz",
106
- "enabled": "@boolean@",
107
- "roles": "@array@"
108
- },
109
- {
110
- "id": "@integer@",
111
- "firstName": "Michał",
112
- "lastName": "Dąbrowski",
113
- "enabled": "expr(value == false)",
114
- "roles": "@array@"
115
- }
116
- ],
117
- "prevPage": "@string@",
118
- "nextPage": "@string@"
119
- } ' ;
120
-
121
80
$ this ->assertTrue ($ this ->matcher ->match ($ json , $ jsonPattern ));
122
81
$ this ->assertTrue (PHPMatcher::match ($ json , $ jsonPattern ));
123
82
}
124
83
84
+ public function jsonDataProvider ()
85
+ {
86
+ return array (
87
+ 'matches exactly ' => array (
88
+ /** @lang JSON */
89
+ '{
90
+ "users":[
91
+ {
92
+ "id": 131,
93
+ "firstName": "Norbert",
94
+ "lastName": "Orzechowicz",
95
+ "enabled": true,
96
+ "roles": ["ROLE_DEVELOPER"]
97
+ },
98
+ {
99
+ "id": 132,
100
+ "firstName": "Michał",
101
+ "lastName": "Dąbrowski",
102
+ "enabled": false,
103
+ "roles": ["ROLE_DEVELOPER"]
104
+ }
105
+ ],
106
+ "prevPage": "http:\/\/example.com\/api\/users\/1?limit=2",
107
+ "nextPage": "http:\/\/example.com\/api\/users\/3?limit=2"
108
+ } ' ,
109
+ /** @lang JSON */
110
+ '{
111
+ "users":[
112
+ {
113
+ "id": "@integer@",
114
+ "firstName":"Norbert",
115
+ "lastName":"Orzechowicz",
116
+ "enabled": "@boolean@",
117
+ "roles": "@array@"
118
+ },
119
+ {
120
+ "id": "@integer@",
121
+ "firstName": "Michał",
122
+ "lastName": "Dąbrowski",
123
+ "enabled": "expr(value == false)",
124
+ "roles": "@array@"
125
+ }
126
+ ],
127
+ "prevPage": "@string@",
128
+ "nextPage": "@string@"
129
+ } ' ,
130
+ ),
131
+ 'matches none elements - empty array ' => array (
132
+ /** @lang JSON */
133
+ '{
134
+ "users":[],
135
+ "prevPage": "http:\/\/example.com\/api\/users\/1?limit=2",
136
+ "nextPage": "http:\/\/example.com\/api\/users\/3?limit=2"
137
+ } ' ,
138
+ /** @lang JSON */
139
+ '{
140
+ "users":[
141
+ "@...@"
142
+ ],
143
+ "prevPage": "@string@",
144
+ "nextPage": "@string@"
145
+ } ' ,
146
+ ),
147
+ 'matches one element ' => array (
148
+ /** @lang JSON */
149
+ '{
150
+ "users":[
151
+ {
152
+ "id": 131,
153
+ "firstName": "Norbert",
154
+ "lastName": "Orzechowicz",
155
+ "enabled": true,
156
+ "roles": ["ROLE_DEVELOPER"]
157
+ }
158
+ ],
159
+ "prevPage": "http:\/\/example.com\/api\/users\/1?limit=2",
160
+ "nextPage": "http:\/\/example.com\/api\/users\/3?limit=2"
161
+ } ' ,
162
+ /** @lang JSON */
163
+ '{
164
+ "users":[
165
+ {
166
+ "id": "@integer@",
167
+ "firstName":"Norbert",
168
+ "lastName":"Orzechowicz",
169
+ "enabled": "@boolean@",
170
+ "roles": "@array@"
171
+ },
172
+ "@...@"
173
+ ],
174
+ "prevPage": "@string@",
175
+ "nextPage": "@string@"
176
+ } ' ,
177
+ ),
178
+ );
179
+ }
180
+
125
181
public function test_matcher_with_xml ()
126
182
{
127
183
$ xml = <<<XML
@@ -284,7 +340,7 @@ public static function nullExamples()
284
340
'{"proformaInvoiceLink":null} ' , '{"proformaInvoiceLink":null} ' ,
285
341
'{"proformaInvoiceLink":null, "test":"test"} ' , '{"proformaInvoiceLink":null, "test":"@string@"} ' ,
286
342
'{"proformaInvoiceLink":null, "test":"test"} ' , '{"proformaInvoiceLink":@null@, "test":"@string@"} ' ,
287
- )
343
+ ),
288
344
);
289
345
}
290
346
}
0 commit comments