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 class it is evaluated for has a given
15 * The attribute name is passed in the constructor.
17 * @since Class available since Release 3.1.0
19 class PHPUnit_Framework_Constraint_ClassHasAttribute extends PHPUnit_Framework_Constraint
24 protected $attributeName;
27 * @param string $attributeName
29 public function __construct($attributeName)
31 parent::__construct();
32 $this->attributeName = $attributeName;
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 $class = new ReflectionClass($other);
47 return $class->hasProperty($this->attributeName);
51 * Returns a string representation of the constraint.
55 public function toString()
64 * Returns the description of the failure
66 * The beginning of failure messages is "Failed asserting that" in most
67 * cases. This method should return the second part of that sentence.
69 * @param mixed $other Evaluated value or object.
73 protected function failureDescription($other)
77 is_object($other) ? 'object of ' : '',
78 is_object($other) ? get_class($other) : $other,