Skip to content

Add casting to bool for expression regex matches #41

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
Dec 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/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/")'),
);
}
}