c05f17259a02dc9188a9a31a2ae1e910abe6b5c2
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Constraint / Exception.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_Exception extends PHPUnit_Framework_Constraint
15 {
16     /**
17      * @var string
18      */
19     protected $className;
20
21     /**
22      * @param string $className
23      */
24     public function __construct($className)
25     {
26         parent::__construct();
27         $this->className = $className;
28     }
29
30     /**
31      * Evaluates the constraint for parameter $other. Returns true if the
32      * constraint is met, false otherwise.
33      *
34      * @param mixed $other Value or object to evaluate.
35      *
36      * @return bool
37      */
38     protected function matches($other)
39     {
40         return $other instanceof $this->className;
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         if ($other !== null) {
56             $message = '';
57             if ($other instanceof Exception) {
58                 $message = '. Message was: "' . $other->getMessage() . '" at'
59                         . "\n" . $other->getTraceAsString();
60             }
61
62             return sprintf(
63                 'exception of type "%s" matches expected exception "%s"%s',
64                 get_class($other),
65                 $this->className,
66                 $message
67             );
68         }
69
70         return sprintf(
71             'exception of type "%s" is thrown',
72             $this->className
73         );
74     }
75
76     /**
77      * Returns a string representation of the constraint.
78      *
79      * @return string
80      */
81     public function toString()
82     {
83         return sprintf(
84             'exception of type "%s"',
85             $this->className
86         );
87     }
88 }