Skip to content

Commit ed142bd

Browse files
committed
Added json matcher test
1 parent b817283 commit ed142bd

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

tests/JsonMatcher/MatcherTest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use JsonMatcher\Matcher\ArrayMatcher;
55
use JsonMatcher\Matcher\ChainMatcher;
6+
use JsonMatcher\Matcher\JsonMatcher;
67
use JsonMatcher\Matcher\ScalarMatcher;
78
use JsonMatcher\Matcher\TypeMatcher;
89
use JsonMatcher\Matcher\WildcardMatcher;
@@ -21,9 +22,13 @@ public function setUp()
2122
new ScalarMatcher(),
2223
new WildcardMatcher()
2324
));
25+
26+
$arrayMatcher = new ArrayMatcher($scalarMatchers);
27+
2428
$this->matcher = new Matcher(new ChainMatcher(array(
2529
$scalarMatchers,
26-
new ArrayMatcher($scalarMatchers)
30+
$arrayMatcher,
31+
new JsonMatcher($arrayMatcher)
2732
)));
2833

2934
$this->arrayValue = array(
@@ -82,4 +87,53 @@ public function test_matcher_with_scalar_values()
8287
'@double@'
8388
));
8489
}
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+
}
85139
}

0 commit comments

Comments
 (0)