You are here

public static function PHPUnit_Framework_Assert::getStaticAttribute in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/Assert.php \PHPUnit_Framework_Assert::getStaticAttribute()

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

@since Method available since Release 4.0.0

Parameters

string $className:

string $attributeName:

Return value

mixed

Throws

PHPUnit_Framework_Exception

6 calls to PHPUnit_Framework_Assert::getStaticAttribute()
Framework_AssertTest::testGetStaticAttributeRaisesExceptionForInvalidFirstArgument in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::getStaticAttribute @expectedException PHPUnit_Framework_Exception
Framework_AssertTest::testGetStaticAttributeRaisesExceptionForInvalidFirstArgument2 in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::getStaticAttribute @expectedException PHPUnit_Framework_Exception
Framework_AssertTest::testGetStaticAttributeRaisesExceptionForInvalidSecondArgument in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::getStaticAttribute @expectedException PHPUnit_Framework_Exception
Framework_AssertTest::testGetStaticAttributeRaisesExceptionForInvalidSecondArgument2 in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::getStaticAttribute @expectedException PHPUnit_Framework_Exception
Framework_AssertTest::testGetStaticAttributeRaisesExceptionForInvalidSecondArgument3 in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::getStaticAttribute @expectedException PHPUnit_Framework_Exception

... See full list

File

vendor/phpunit/phpunit/src/Framework/Assert.php, line 2881

Class

PHPUnit_Framework_Assert
A set of assert methods.

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');
  }
  if (!preg_match('/[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/', $attributeName)) {
    throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'valid attribute name');
  }
  $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));
}