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 11/** 12 * Constraint that asserts that the class it is evaluated for has a given 13 * static attribute. 14 * 15 * The attribute name is passed in the constructor. 16 */ 17class PHPUnit_Framework_Constraint_ClassHasStaticAttribute extends PHPUnit_Framework_Constraint_ClassHasAttribute 18{ 19 /** 20 * Evaluates the constraint for parameter $other. Returns true if the 21 * constraint is met, false otherwise. 22 * 23 * @param mixed $other Value or object to evaluate. 24 * 25 * @return bool 26 */ 27 protected function matches($other) 28 { 29 $class = new ReflectionClass($other); 30 31 if ($class->hasProperty($this->attributeName)) { 32 $attribute = $class->getProperty($this->attributeName); 33 34 return $attribute->isStatic(); 35 } else { 36 return false; 37 } 38 } 39 40 /** 41 * Returns a string representation of the constraint. 42 * 43 * @return string 44 */ 45 public function toString() 46 { 47 return sprintf( 48 'has static attribute "%s"', 49 $this->attributeName 50 ); 51 } 52} 53