*/ class UnitTestHelper extends \PHPUnit_Framework_TestCase { protected $instance; protected function getInaccessibleProperty($object , $propertyName) { $property = new \ReflectionProperty(get_class($object) , $propertyName); $property->setAccessible(true); $value = $property->getValue($object); $property->setAccessible(false); return $value; } protected function setInaccessibleProperty($object , $propertyName, $value) { $property = new \ReflectionProperty(get_class($object) , $propertyName); $property->setAccessible(true); $property->setValue($object, $value); $property->setAccessible(false); return $this; } protected function callInaccessibleMethod($methodName , array $arguments = []) { $method = new \ReflectionMethod(get_class($this->instance) , $methodName); $method->setAccessible(true); $result = $method->invokeArgs($this->instance, $arguments); $method->setAccessible(false); return $result; } /** * 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 invokeProtectedMethod($object, $methodName, array $parameters = array()) { $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); $method->setAccessible(true); return $method->invokeArgs($object, $parameters); } }