Skip to content

Commit c6c5396

Browse files
author
Kacper Gunia
committed
Add casting to bool for expression regex matches
1 parent 4e37e27 commit c6c5396

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function match($value, $pattern)
2222
$this->error = sprintf("\"%s\" expression fails for value \"%s\".", $pattern, new String($value));
2323
}
2424

25-
return $expressionResult;
25+
return (bool) $expressionResult;
2626
}
2727

2828
/**

tests/Coduo/PHPMatcher/Matcher/ExpressionMatcherTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ public function test_negative_match_description($value, $pattern, $error)
5151
$this->assertEquals($error, $matcher->getError());
5252
}
5353

54+
/**
55+
* @dataProvider positiveRegexMatchData
56+
*/
57+
public function test_positive_regex_matches($value, $pattern)
58+
{
59+
$matcher = new ExpressionMatcher();
60+
$this->assertTrue($matcher->match($value, $pattern));
61+
}
62+
63+
/**
64+
* @dataProvider negativeRegexMatchData
65+
*/
66+
public function test_negative_regex_matches($value, $pattern)
67+
{
68+
$matcher = new ExpressionMatcher();
69+
$this->assertFalse($matcher->match($value, $pattern));
70+
}
71+
5472
public static function positiveCanMatchData()
5573
{
5674
return array(
@@ -98,4 +116,20 @@ public static function negativeMatchDescription()
98116
),
99117
);
100118
}
119+
120+
public static function positiveRegexMatchData()
121+
{
122+
return array(
123+
array('Cakper', 'expr(value matches "/Cakper/")'),
124+
array('Cakper', 'expr(not(value matches "/Yaboomaster/"))'),
125+
);
126+
}
127+
128+
public static function negativeRegexMatchData()
129+
{
130+
return array(
131+
array('Cakper', 'expr(not(value matches "/Cakper/"))'),
132+
array('Cakper', 'expr(value matches "/Yaboomaster/")'),
133+
);
134+
}
101135
}

0 commit comments

Comments
 (0)