Skip to content

Expanded TRANSFORM_QUOTATION_PATTERN in Json matcher to handle new type matchers #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Coduo/PHPMatcher/Matcher/JsonMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

/**
Expand Down
38 changes: 38 additions & 0 deletions tests/Coduo/PHPMatcher/Matcher/JsonMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public function test_positive_matches($value, $pattern)
$this->assertTrue($this->matcher->match($value, $pattern), $this->matcher->getError());
}

/**
* @dataProvider normalizationRequiredDataProvider
*/
public function test_positive_matches_after_normalization($value, $pattern)
{
$this->assertTrue($this->matcher->match($value, $pattern), $this->matcher->getError());
}

/**
* @dataProvider negativeMatches
*/
Expand Down Expand Up @@ -193,4 +201,34 @@ public static function negativeMatches()
)
);
}

public static function normalizationRequiredDataProvider()
{
return array(
array(
'{"name": "Norbert"}',
'{"name": @string@}'
),
array(
'{"name": 25}',
'{"name": @number@}'
),
array(
'{"name": 25}',
'{"name": @integer@}'
),
array(
'{"name": true}',
'{"name": @boolean@}'
),
array(
'{"name": ["Norbert", "Michał"]}',
'{"name": ["Norbert", @...@]}'
),
array(
'{"name": "Norbert", "roles": ["ADMIN", "USER"]}',
'{"name": @string@, "roles": [@string@, @string@]}'
),
);
}
}