/** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * @param Exception $other * * @return bool */ protected function matches($other) { $match = PHPUnit_Util_Regex::pregMatchSafe($this->expectedMessageRegExp, $other->getMessage()); if (false === $match) { throw new PHPUnit_Framework_Exception("Invalid expected exception message regex given: '{$this->expectedMessageRegExp}'"); } return 1 === $match; }
/** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * @param Exception $other * @return boolean */ protected function matches($other) { $match = PHPUnit_Util_Regex::pregMatchSafe($this->expectedMessage, $other->getMessage()); if (false !== $match) { $this->regexBased = true; } else { $match = strpos($other->getMessage(), $this->expectedMessage) !== false; } return (bool) $match; }
/** * @param string $filter */ protected function setFilter($filter) { if (PHPUnit_Util_Regex::pregMatchSafe($filter, '') === FALSE) { // Handles: // * testAssertEqualsSucceeds#4 // * testAssertEqualsSucceeds#4-8 if (preg_match('/^(.*?)#(\\d+)(?:-(\\d+))?$/', $filter, $matches)) { if (isset($matches[3]) && $matches[2] < $matches[3]) { $filter = sprintf('%s.*with data set #(\\d+)$', $matches[1]); $this->filterMin = $matches[2]; $this->filterMax = $matches[3]; } else { $filter = sprintf('%s.*with data set #%s$', $matches[1], $matches[2]); } } elseif (preg_match('/^(.*?)@(.+)$/', $filter, $matches)) { $filter = sprintf('%s.*with data set "%s"$', $matches[1], $matches[2]); } // Escape delimiters in regular expression. Do NOT use preg_quote, // to keep magic characters. $filter = sprintf('/%s/', str_replace('/', '\\/', $filter)); } $this->filter = $filter; }
/** * @dataProvider invalidRegexpProvider * @covers PHPUnit_Util_Regex::pregMatchSafe */ public function testInvalidRegex($pattern, $subject) { $this->assertFalse(PHPUnit_Util_Regex::pregMatchSafe($pattern, $subject)); }