From 585d80a0b3b6b5334bbe9b6ae45d9a3cce16b831 Mon Sep 17 00:00:00 2001 From: Adam Quaile Date: Wed, 7 Jan 2015 10:32:01 +0000 Subject: [PATCH] TextMatcher cannot match @null@ inside pattern --- src/Coduo/PHPMatcher/Matcher/TextMatcher.php | 4 ++++ tests/Coduo/PHPMatcher/Matcher/TextMatcherTest.php | 14 ++++++++++++++ text-matcher-bug.php | 0 3 files changed, 18 insertions(+) create mode 100644 text-matcher-bug.php diff --git a/src/Coduo/PHPMatcher/Matcher/TextMatcher.php b/src/Coduo/PHPMatcher/Matcher/TextMatcher.php index 4a5d0de6..431941b1 100644 --- a/src/Coduo/PHPMatcher/Matcher/TextMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/TextMatcher.php @@ -79,6 +79,10 @@ public function canMatch($pattern) return false; } + if (mb_strlen($pattern) !== 6 && false !== mb_strpos($pattern, '@null@')) { + return false; + } + return true; } diff --git a/tests/Coduo/PHPMatcher/Matcher/TextMatcherTest.php b/tests/Coduo/PHPMatcher/Matcher/TextMatcherTest.php index 79f2800f..343ed336 100644 --- a/tests/Coduo/PHPMatcher/Matcher/TextMatcherTest.php +++ b/tests/Coduo/PHPMatcher/Matcher/TextMatcherTest.php @@ -37,6 +37,20 @@ public function setUp() ); } + public function test_can_match_general_strings() + { + $this->assertTrue($this->matcher->canMatch('')); + $this->assertTrue($this->matcher->canMatch('String with text')); + $this->assertTrue($this->matcher->canMatch('String with text, @number@ and @*@')); + } + + public function test_cannot_match_null_as_part_of_pattern() + { + $this->assertFalse($this->matcher->canMatch("Using @null@ inside other text")); + $this->assertFalse($this->matcher->canMatch("@null@ at start of pattern")); + $this->assertFalse($this->matcher->canMatch("pattern ends with @null@")); + } + /** * @dataProvider matchingData */ diff --git a/text-matcher-bug.php b/text-matcher-bug.php new file mode 100644 index 00000000..e69de29b