Version 1
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Constraint / ExceptionMessage.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 3.6.6
13  */
14 class PHPUnit_Framework_Constraint_ExceptionMessage extends PHPUnit_Framework_Constraint
15 {
16     /**
17      * @var int
18      */
19     protected $expectedMessage;
20
21     /**
22      * @param string $expected
23      */
24     public function __construct($expected)
25     {
26         parent::__construct();
27         $this->expectedMessage = $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         return strpos($other->getMessage(), $this->expectedMessage) !== false;
41     }
42
43     /**
44      * Returns the description of the failure
45      *
46      * The beginning of failure messages is "Failed asserting that" in most
47      * cases. This method should return the second part of that sentence.
48      *
49      * @param mixed $other Evaluated value or object.
50      *
51      * @return string
52      */
53     protected function failureDescription($other)
54     {
55         return sprintf(
56             "exception message '%s' contains '%s'",
57             $other->getMessage(),
58             $this->expectedMessage
59         );
60     }
61
62     /**
63      * @return string
64      */
65     public function toString()
66     {
67         return 'exception message contains ';
68     }
69 }