Skip to content

Instantly share code, notes, and snippets.

@Mulkave
Last active December 18, 2015 12:18
Show Gist options
  • Save Mulkave/5781352 to your computer and use it in GitHub Desktop.
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
<?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