Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCase.php
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | abstract class TestCase extends BaseTestCase | ||||
protected static function getObjectProperty($object, $property_name) | protected static function getObjectProperty($object, $property_name) | ||||
{ | { | ||||
$reflection = new \ReflectionClass($object); | $reflection = new \ReflectionClass($object); | ||||
$property = $reflection->getProperty($property_name); | $property = $reflection->getProperty($property_name); | ||||
$property->setAccessible(true); | $property->setAccessible(true); | ||||
return $property->getValue($object); | return $property->getValue($object); | ||||
} | } | ||||
/** | |||||
* Call protected/private method of a class. | |||||
* | |||||
* @param object $object Instantiated object that we will run method on. | |||||
* @param string $methodName Method name to call | |||||
* @param array $parameters Array of parameters to pass into method. | |||||
* | |||||
* @return mixed Method return. | |||||
*/ | |||||
public function invokeMethod($object, $methodName, array $parameters = array()) | |||||
{ | |||||
$reflection = new \ReflectionClass(get_class($object)); | |||||
$method = $reflection->getMethod($methodName); | |||||
$method->setAccessible(true); | |||||
return $method->invokeArgs($object, $parameters); | |||||
} | |||||
} | } |