getObjectAttribute() публичный статический Метод

This also works for attributes that are declared protected or private.
public static getObjectAttribute ( object $object, string $attributeName ) : mixed
$object object
$attributeName string
Результат mixed
 /**
  * @dataProvider handlerProvider
  */
 public function testManufactureHandlers($types, $options)
 {
     $handler = HandlerFactory::createHandler($types, $options);
     if (count($types) > 1) {
         $handlerclass = $this->handlers['Composite'];
         $h = \PHPUnit_Util_Class::getObjectAttribute($handler, 'drivers');
         $handlers = array_combine($types, $h);
     } else {
         $handlerclass = $this->handlers[$types[0]];
         $handlers = array($types[0] => $handler);
     }
     $this->assertInstanceOf($handlerclass, $handler);
     foreach ($handlers as $subtype => $subhandler) {
         $subhandlerclass = $this->handlers[$subtype];
         $this->assertInstanceOf($subhandlerclass, $subhandler);
     }
     foreach ($types as $type) {
         $defaults = isset($this->defaultSettings[$type]) ? $this->defaultSettings[$type] : array();
         $options = array_merge($defaults, $options);
         /*            foreach($options as $optname => $optvalue) {
                         $this->assertAttributeEquals($optvalue, $optname, $handlers[$type]);
                     }
         */
     }
 }
Пример #2
0
 /**
  * Test that if a dynamic variable is defined on a class then
  * the $attribute variable will be NULL, but the variable defined
  * will be a public one so we are safe to return it
  *
  * Currently $attribute is NULL but we try and call isPublic() on it.
  * This breaks for php 5.2.10
  *
  * @covers PHPUnit_Util_Class::getObjectAttribute
  *
  * @return void
  */
 public function testGetObjectAttributeCanHandleDynamicVariables()
 {
     $attributeName = '_variable';
     $object = new stdClass();
     $object->{$attributeName} = 'Test';
     $actual = PHPUnit_Util_Class::getObjectAttribute($object, $attributeName);
     $this->assertEquals('Test', $actual);
 }
Пример #3
0
 /**
  * Test setThreshold method
  */
 public function testSetThreshold()
 {
     $thresholdKey = Magento_Profiler_Driver_Standard_Stat::TIME;
     $this->_output->setThreshold($thresholdKey, 100);
     $thresholds = PHPUnit_Util_Class::getObjectAttribute($this->_output, '_thresholds');
     $this->assertArrayHasKey($thresholdKey, $thresholds);
     $this->assertEquals(100, $thresholds[$thresholdKey]);
     $this->_output->setThreshold($thresholdKey, null);
     $this->assertArrayNotHasKey($thresholdKey, $this->_output->getThresholds());
 }
 /**
  * Test setThreshold method
  */
 public function testSetThreshold()
 {
     $thresholdKey = \Magento\Framework\Profiler\Driver\Standard\Stat::TIME;
     $this->_output->setThreshold($thresholdKey, 100);
     $thresholds = class_exists('PHPUnit_Util_Class') ? \PHPUnit_Util_Class::getObjectAttribute($this->_output, '_thresholds') : \PHPUnit_Framework_Assert::readAttribute($this->_output, '_thresholds');
     $this->assertArrayHasKey($thresholdKey, $thresholds);
     $this->assertEquals(100, $thresholds[$thresholdKey]);
     $this->_output->setThreshold($thresholdKey, null);
     $this->assertArrayNotHasKey($thresholdKey, $this->_output->getThresholds());
 }
Пример #5
0
 /**
  * Returns the value of an attribute of a class or an object.
  * This also works for attributes that are declared protected or private.
  *
  * @param  mixed   $classOrObject
  * @param  string  $attributeName
  * @return mixed
  * @throws PHPUnit_Framework_Exception
  */
 public static function readAttribute($classOrObject, $attributeName)
 {
     if (!is_string($attributeName)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
     }
     if (is_string($classOrObject)) {
         if (!class_exists($classOrObject)) {
             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class name');
         }
         return PHPUnit_Util_Class::getStaticAttribute($classOrObject, $attributeName);
     } else {
         if (is_object($classOrObject)) {
             return PHPUnit_Util_Class::getObjectAttribute($classOrObject, $attributeName);
         } else {
             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class name or object');
         }
     }
 }
 /**
  * Tests access to data stored in {@link phpucAbstractAntTask::$properties}
  *
  * @covers phpucAbstractAntTask::__set
  * @covers phpucAbstractAntTask::__get
  * @covers phpucAbstractAntTask::__isset
  *
  * @return void
  */
 public function testDefinedProperties()
 {
     $buildFile = $this->getMock('phpucBuildFile', array(), array(), '', false);
     $exec = phpucAbstractAntTask::create($buildFile, 'exec');
     $php = 'php5';
     $exec->executable = $php;
     $properties = PHPUnit_Util_Class::getObjectAttribute($exec, 'properties');
     $this->assertEquals($php, $properties['executable']);
     $this->assertEquals($php, $exec->executable);
     $this->assertTrue(isset($exec->executable));
     $this->assertFalse(isset($exec->foobar));
 }
Пример #7
0
 /**
  * Tests that {@link phpucAbstractAntTask} are properly added to
  * target tasks list
  *
  * @covers phpucBuildTarget::addTask
  * @covers phpucBuildTarget::getTasks
  *
  * @return void
  */
 public function testTargetTasks()
 {
     $buildFile = new phpucBuildFile($this->fileName, $this->projectName);
     $target = $buildFile->createBuildTarget('phpuc');
     $execTask = phpucAbstractAntTask::create($buildFile, 'exec');
     $applyTask = phpucAbstractAntTask::create($buildFile, 'apply');
     $target->addTask($execTask);
     $target->addTask($applyTask);
     $this->assertEquals(array($execTask, $applyTask), $target->getTasks());
     $tasks = PHPUnit_Util_Class::getObjectAttribute($target, 'tasks');
     $this->assertEquals(array($execTask, $applyTask), $tasks);
 }