Constraint that asserts that the class it is evaluated for has a given static attribute.
The attribute name is passed in the constructor.
@package PHPUnit @subpackage Framework_Constraint @author Sebastian Bergmann <sebastian@phpunit.de> @author Bernhard Schussek <bschussek@2bepublished.at> @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de> @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License @link http://www.phpunit.de/ @since Class available since Release 3.1.0
Expanded class hierarchy of PHPUnit_Framework_Constraint_ClassHasStaticAttribute
class PHPUnit_Framework_Constraint_ClassHasStaticAttribute extends PHPUnit_Framework_Constraint_ClassHasAttribute {
/**
* Evaluates the constraint for parameter $other. Returns TRUE if the
* constraint is met, FALSE otherwise.
*
* @param mixed $other Value or object to evaluate.
* @return bool
*/
protected function matches($other) {
$class = new ReflectionClass($other);
if ($class
->hasProperty($this->attributeName)) {
$attribute = $class
->getProperty($this->attributeName);
return $attribute
->isStatic();
}
else {
return FALSE;
}
}
/**
* Returns a string representation of the constraint.
*
* @return string
* @since Method available since Release 3.3.0
*/
public function toString() {
return sprintf('has static attribute "%s"', $this->attributeName);
}
}