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 11class PHPUnit_Framework_Constraint_ExceptionCode extends PHPUnit_Framework_Constraint 12{ 13 /** 14 * @var int 15 */ 16 protected $expectedCode; 17 18 /** 19 * @param int $expected 20 */ 21 public function __construct($expected) 22 { 23 parent::__construct(); 24 $this->expectedCode = $expected; 25 } 26 27 /** 28 * Evaluates the constraint for parameter $other. Returns true if the 29 * constraint is met, false otherwise. 30 * 31 * @param Exception $other 32 * 33 * @return bool 34 */ 35 protected function matches($other) 36 { 37 return (string) $other->getCode() == (string) $this->expectedCode; 38 } 39 40 /** 41 * Returns the description of the failure 42 * 43 * The beginning of failure messages is "Failed asserting that" in most 44 * cases. This method should return the second part of that sentence. 45 * 46 * @param mixed $other Evaluated value or object. 47 * 48 * @return string 49 */ 50 protected function failureDescription($other) 51 { 52 return sprintf( 53 '%s is equal to expected exception code %s', 54 $this->exporter->export($other->getCode()), 55 $this->exporter->export($this->expectedCode) 56 ); 57 } 58 59 /** 60 * @return string 61 */ 62 public function toString() 63 { 64 return 'exception code is '; 65 } 66} 67