Version 1
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Constraint / ExceptionCode.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_ExceptionCode extends PHPUnit_Framework_Constraint
15 {
16     /**
17      * @var int
18      */
19     protected $expectedCode;
20
21     /**
22      * @param int $expected
23      */
24     public function __construct($expected)
25     {
26         parent::__construct();
27         $this->expectedCode = $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 (string) $other->getCode() == (string) $this->expectedCode;
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             '%s is equal to expected exception code %s',
57             $this->exporter->export($other->getCode()),
58             $this->exporter->export($this->expectedCode)
59         );
60     }
61
62     /**
63      * @return string
64      */
65     public function toString()
66     {
67         return 'exception code is ';
68     }
69 }