PHPUnit_Framework_Assert::readAttribute PHP Method

readAttribute() public static method

This also works for attributes that are declared protected or private.
public static readAttribute ( string | object $classOrObject, string $attributeName ) : mixed
$classOrObject string | object
$attributeName string
return mixed
    public static function readAttribute($classOrObject, $attributeName)
    {
        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');
        }
        if (is_string($classOrObject)) {
            if (!class_exists($classOrObject)) {
                throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class name');
            }
            return static::getStaticAttribute($classOrObject, $attributeName);
        } elseif (is_object($classOrObject)) {
            return static::getObjectAttribute($classOrObject, $attributeName);
        } else {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class name or object');
        }
    }

Usage Example

 /**
  * @test
  */
 public function it_applies_the_requested_relationship_to_the_query()
 {
     /** @var ModelStub $model */
     $model = reader::readAttribute($this->repo, 'model');
     $this->repo->with('all')->getAll();
     $this->assertEquals(['author', 'comments'], $model->getRequestedRelationships());
 }
All Usage Examples Of PHPUnit_Framework_Assert::readAttribute
PHPUnit_Framework_Assert