Skip to content

Commit 4e37e27

Browse files
committedNov 11, 2014
Merge pull request #38 from norzechowicz/json-normalizer
Expanded TRANSFORM_QUOTATION_PATTERN in Json matcher to handle new type matchers
2 parents 7c621db + f5b6d23 commit 4e37e27

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
 

‎src/Coduo/PHPMatcher/Matcher/JsonMatcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class JsonMatcher extends Matcher
66
{
7-
const TRANSFORM_QUOTATION_PATTERN = '/([^"])@(integer|string|array|double|wildcard|boolean|\.\.\.|null)@([^"])/';
7+
const TRANSFORM_QUOTATION_PATTERN = '/([^"])@([a-zA-Z0-9\.]+)@([^"])/';
88
const TRANSFORM_QUOTATION_REPLACEMENT = '$1"@$2@"$3';
99

1010
/**

‎tests/Coduo/PHPMatcher/Matcher/JsonMatcherTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public function test_positive_matches($value, $pattern)
5858
$this->assertTrue($this->matcher->match($value, $pattern), $this->matcher->getError());
5959
}
6060

61+
/**
62+
* @dataProvider normalizationRequiredDataProvider
63+
*/
64+
public function test_positive_matches_after_normalization($value, $pattern)
65+
{
66+
$this->assertTrue($this->matcher->match($value, $pattern), $this->matcher->getError());
67+
}
68+
6169
/**
6270
* @dataProvider negativeMatches
6371
*/
@@ -193,4 +201,34 @@ public static function negativeMatches()
193201
)
194202
);
195203
}
204+
205+
public static function normalizationRequiredDataProvider()
206+
{
207+
return array(
208+
array(
209+
'{"name": "Norbert"}',
210+
'{"name": @string@}'
211+
),
212+
array(
213+
'{"name": 25}',
214+
'{"name": @number@}'
215+
),
216+
array(
217+
'{"name": 25}',
218+
'{"name": @integer@}'
219+
),
220+
array(
221+
'{"name": true}',
222+
'{"name": @boolean@}'
223+
),
224+
array(
225+
'{"name": ["Norbert", "Michał"]}',
226+
'{"name": ["Norbert", @...@]}'
227+
),
228+
array(
229+
'{"name": "Norbert", "roles": ["ADMIN", "USER"]}',
230+
'{"name": @string@, "roles": [@string@, @string@]}'
231+
),
232+
);
233+
}
196234
}

0 commit comments

Comments
 (0)