3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Constraint that asserts that the object it is evaluated for is an instance
15 * The expected class name is passed in the constructor.
17 * @since Class available since Release 3.0.0
19 class PHPUnit_Framework_Constraint_IsInstanceOf extends PHPUnit_Framework_Constraint
27 * @param string $className
29 public function __construct($className)
31 parent::__construct();
32 $this->className = $className;
36 * Evaluates the constraint for parameter $other. Returns true if the
37 * constraint is met, false otherwise.
39 * @param mixed $other Value or object to evaluate.
43 protected function matches($other)
45 return ($other instanceof $this->className);
49 * Returns the description of the failure
51 * The beginning of failure messages is "Failed asserting that" in most
52 * cases. This method should return the second part of that sentence.
54 * @param mixed $other Evaluated value or object.
58 protected function failureDescription($other)
61 '%s is an instance of %s "%s"',
62 $this->exporter->shortenedExport($other),
69 * Returns a string representation of the constraint.
73 public function toString()
76 'is instance of %s "%s"',
82 private function getType()
85 $reflection = new ReflectionClass($this->className);
86 if ($reflection->isInterface()) {
89 } catch (ReflectionException $e) {