Skip to content

Commit

Permalink
Merge pull request #41 from cakper/fix-regex-matcher-edge-case
Browse files Browse the repository at this point in the history
Add casting to bool for expression regex matches
  • Loading branch information
Norbert Orzechowicz committed Dec 11, 2014
2 parents 4e37e27 + c6c5396 commit 6298c3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function match($value, $pattern)
$this->error = sprintf("\"%s\" expression fails for value \"%s\".", $pattern, new String($value));
}

return $expressionResult;
return (bool) $expressionResult;
}

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/Coduo/PHPMatcher/Matcher/ExpressionMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ public function test_negative_match_description($value, $pattern, $error)
$this->assertEquals($error, $matcher->getError());
}

/**
* @dataProvider positiveRegexMatchData
*/
public function test_positive_regex_matches($value, $pattern)
{
$matcher = new ExpressionMatcher();
$this->assertTrue($matcher->match($value, $pattern));
}

/**
* @dataProvider negativeRegexMatchData
*/
public function test_negative_regex_matches($value, $pattern)
{
$matcher = new ExpressionMatcher();
$this->assertFalse($matcher->match($value, $pattern));
}

public static function positiveCanMatchData()
{
return array(
Expand Down Expand Up @@ -98,4 +116,20 @@ public static function negativeMatchDescription()
),
);
}

public static function positiveRegexMatchData()
{
return array(
array('Cakper', 'expr(value matches "/Cakper/")'),
array('Cakper', 'expr(not(value matches "/Yaboomaster/"))'),
);
}

public static function negativeRegexMatchData()
{
return array(
array('Cakper', 'expr(not(value matches "/Cakper/"))'),
array('Cakper', 'expr(value matches "/Yaboomaster/")'),
);
}
}

0 comments on commit 6298c3c

Please sign in to comment.