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.
18
* @subpackage Framework_Constraint
19
* @author Sebastian Bergmann <sebastian@phpunit.de>
20
* @author Bernhard Schussek <bschussek@2bepublished.at>
21
* @copyright Sebastian Bergmann <sebastian@phpunit.de>
22
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
23
* @link http://www.phpunit.de/
24
* @since Class available since Release 3.1.0
26
class PHPUnit_Framework_Constraint_ClassHasAttribute extends PHPUnit_Framework_Constraint
31
protected $attributeName;
34
* @param string $attributeName
36
public function __construct($attributeName)
38
parent::__construct();
39
$this->attributeName = $attributeName;
43
* Evaluates the constraint for parameter $other. Returns true if the
44
* constraint is met, false otherwise.
46
* @param mixed $other Value or object to evaluate.
49
protected function matches($other)
51
$class = new ReflectionClass($other);
53
return $class->hasProperty($this->attributeName);
57
* Returns a string representation of the constraint.
61
public function toString()
70
* Returns the description of the failure
72
* The beginning of failure messages is "Failed asserting that" in most
73
* cases. This method should return the second part of that sentence.
75
* @param mixed $other Evaluated value or object.
78
protected function failureDescription($other)
82
is_object($other) ? 'object of ' : '',
83
is_object($other) ? get_class($other) : $other,