Skip to content

Instantly share code, notes, and snippets.

@radmiraal
Created September 19, 2012 07:36
Show Gist options
  • Save radmiraal/3748210 to your computer and use it in GitHub Desktop.
Save radmiraal/3748210 to your computer and use it in GitHub Desktop.
/**
* Call an inaccessible method on an object, marks test skipped if method could not be called
*
* @param object $object An instance of a class
* @param string $methodName Name of the protected method
* @param array $arguments
* @param string $originalClassName Set this value if you want to call methods on a mock object
* @return mixed The return value of the method
*/
protected function callInaccessibleMethod($object, $methodName, array $arguments = array(), $originalClassName = NULL) {
if (version_compare(phpversion(), '5.3.2', '>')) {
try {
$reflectionClass = new \ReflectionClass($originalClassName !== NULL ? $originalClassName : get_class($object));
$method = $reflectionClass->getMethod($methodName);
$method->setAccessible(TRUE);
return $method->invokeArgs($object, $arguments);
} catch (\Exception $exception) {
}
}
$this->markTestSkipped('Can not call inaccessible method');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment