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 * Constraint that asserts that the string it is evaluated for matches
13 * a regular expression.
15 * Checks a given value using the Perl Compatible Regular Expression extension
16 * in PHP. The pattern is matched by executing preg_match().
18 * The pattern string passed in the constructor.
20 * @since Class available since Release 3.0.0
22 class PHPUnit_Framework_Constraint_PCREMatch extends PHPUnit_Framework_Constraint
30 * @param string $pattern
32 public function __construct($pattern)
34 parent::__construct();
35 $this->pattern = $pattern;
39 * Evaluates the constraint for parameter $other. Returns true if the
40 * constraint is met, false otherwise.
42 * @param mixed $other Value or object to evaluate.
46 protected function matches($other)
48 return preg_match($this->pattern, $other) > 0;
52 * Returns a string representation of the constraint.
56 public function toString()
59 'matches PCRE pattern "%s"',