Skip to content

Commit 4de8857

Browse files
committed
Making quotes not necessary
1 parent 4f2a6fa commit 4de8857

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/PHPMatcher/Matcher/JsonMatcher.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function match($value, $pattern)
2626
return false;
2727
}
2828

29+
$pattern = $this->transformPattern($pattern);
2930
return $this->matcher->match(json_decode($value, true), json_decode($pattern, true));
3031
}
3132

@@ -42,4 +43,9 @@ private function isValidJson($string)
4243
@json_decode($string, true);
4344
return (json_last_error() == JSON_ERROR_NONE);
4445
}
46+
47+
private function transformPattern($pattern)
48+
{
49+
return preg_replace('/([^"])@(integer|string|array|double|wildcard|boolean)@([^"])/', '$1"@$2@"$3', $pattern);
50+
}
4551
}

tests/PHPMatcher/Matcher/JsonMatcherTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ public static function positiveMatches()
8484
'{"users":["Norbert","Michał"]}',
8585
'{"users":["@string@","@string@"]}'
8686
),
87+
array(
88+
'{"numbers":[1,2]}',
89+
'{"numbers":[@integer@, @integer@]}'
90+
),
91+
array(
92+
'{"foobar":[1.22, 2, "hello"]}',
93+
'{"foobar":[@double@, @integer@, @string@]}'
94+
),
8795
array(
8896
'{"users":[{"firstName":"Norbert","lastName":"Orzechowicz","roles":["ROLE_USER", "ROLE_DEVELOPER"]}]}',
8997
'{"users":[{"firstName":"Norbert","lastName":"Orzechowicz","roles":"@wildcard@"}]}'

0 commit comments

Comments
 (0)