diff --git a/src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php b/src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php index 380f0e74..3731bbc9 100644 --- a/src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php @@ -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; } /** diff --git a/tests/Coduo/PHPMatcher/Matcher/ExpressionMatcherTest.php b/tests/Coduo/PHPMatcher/Matcher/ExpressionMatcherTest.php index 573285a8..f511fec6 100644 --- a/tests/Coduo/PHPMatcher/Matcher/ExpressionMatcherTest.php +++ b/tests/Coduo/PHPMatcher/Matcher/ExpressionMatcherTest.php @@ -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( @@ -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/")'), + ); + } }