Last active
December 18, 2015 12:18
-
-
Save Mulkave/5781352 to your computer and use it in GitHub Desktop.
A helper method that takes care of passing the protected method out of the class as a public method to be accessible for testing
This file contains 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
<?php | |
Class SomeTest extends PHPUnit_Framework_TestCase { | |
protected static function getProtectedMethod($name, $class) | |
{ | |
$class = new \ReflectionClass(get_class($class)); | |
$method = $class->getMethod($name); | |
$method->setAccessible(true); | |
return $method; | |
} | |
} | |
// calling | |
// $classInstance = new MyClass(); | |
// $myProtectedMethod = static::getProtectedMethod('myProtectedMethod', $classInstance); | |
// $myProtectedMethod->invokeArgs($classInstance, array('arg1', 'arg2')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment