public static function PHPUnit_Util_Class::getStaticAttribute

Returns the value of a static attribute. This also works for attributes that are declared protected or private.

@since Method available since Release 3.4.0

Parameters

string $className:

string $attributeName:

Return value

mixed

Throws

PHPUnit_Framework_Exception

1 call to PHPUnit_Util_Class::getStaticAttribute()
PHPUnit_Framework_Assert::readAttribute in drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/Assert.php
Returns the value of an attribute of a class or an object. This also works for attributes that are declared protected or private.

File

drupal/core/vendor/phpunit/phpunit/PHPUnit/Util/Class.php, line 251

Class

PHPUnit_Util_Class
Class helpers.

Code

public static function getStaticAttribute($className, $attributeName) {
  if (!is_string($className)) {
    throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  }
  if (!class_exists($className)) {
    throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class name');
  }
  if (!is_string($attributeName)) {
    throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  }
  $class = new ReflectionClass($className);
  while ($class) {
    $attributes = $class
      ->getStaticProperties();
    if (array_key_exists($attributeName, $attributes)) {
      return $attributes[$attributeName];
    }
    $class = $class
      ->getParentClass();
  }
  throw new PHPUnit_Framework_Exception(sprintf('Attribute "%s" not found in class.', $attributeName));
}