Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Constraint / ExceptionMessageRegExp.php
1 <?php
2 /*
3  * This file is part of PHPUnit.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * @since Class available since Release 4.3.0
13  */
14 class PHPUnit_Framework_Constraint_ExceptionMessageRegExp extends PHPUnit_Framework_Constraint
15 {
16     /**
17      * @var int
18      */
19     protected $expectedMessageRegExp;
20
21     /**
22      * @param string $expected
23      */
24     public function __construct($expected)
25     {
26         parent::__construct();
27         $this->expectedMessageRegExp = $expected;
28     }
29
30     /**
31      * Evaluates the constraint for parameter $other. Returns true if the
32      * constraint is met, false otherwise.
33      *
34      * @param Exception $other
35      *
36      * @return bool
37      */
38     protected function matches($other)
39     {
40         $match = PHPUnit_Util_Regex::pregMatchSafe($this->expectedMessageRegExp, $other->getMessage());
41
42         if (false === $match) {
43             throw new PHPUnit_Framework_Exception(
44                 "Invalid expected exception message regex given: '{$this->expectedMessageRegExp}'"
45             );
46         }
47
48         return 1 === $match;
49     }
50
51     /**
52      * Returns the description of the failure
53      *
54      * The beginning of failure messages is "Failed asserting that" in most
55      * cases. This method should return the second part of that sentence.
56      *
57      * @param mixed $other Evaluated value or object.
58      *
59      * @return string
60      */
61     protected function failureDescription($other)
62     {
63         return sprintf(
64             "exception message '%s' matches '%s'",
65             $other->getMessage(),
66             $this->expectedMessageRegExp
67         );
68     }
69
70     /**
71      * @return string
72      */
73     public function toString()
74     {
75         return 'exception message matches ';
76     }
77 }