3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * @since Class available since Release 4.3.0
14 class PHPUnit_Framework_Constraint_ExceptionMessageRegExp extends PHPUnit_Framework_Constraint
19 protected $expectedMessageRegExp;
22 * @param string $expected
24 public function __construct($expected)
26 parent::__construct();
27 $this->expectedMessageRegExp = $expected;
31 * Evaluates the constraint for parameter $other. Returns true if the
32 * constraint is met, false otherwise.
34 * @param Exception $other
38 protected function matches($other)
40 $match = PHPUnit_Util_Regex::pregMatchSafe($this->expectedMessageRegExp, $other->getMessage());
42 if (false === $match) {
43 throw new PHPUnit_Framework_Exception(
44 "Invalid expected exception message regex given: '{$this->expectedMessageRegExp}'"
52 * Returns the description of the failure
54 * The beginning of failure messages is "Failed asserting that" in most
55 * cases. This method should return the second part of that sentence.
57 * @param mixed $other Evaluated value or object.
61 protected function failureDescription($other)
64 "exception message '%s' matches '%s'",
66 $this->expectedMessageRegExp
73 public function toString()
75 return 'exception message matches ';