-
-
Save radmiraal/3748210 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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