Skip to content

Instantly share code, notes, and snippets.

@lovelock
Created April 28, 2016 05:20
Show Gist options
  • Save lovelock/422211343fd330ea2ae401888ee8ec30 to your computer and use it in GitHub Desktop.
Save lovelock/422211343fd330ea2ae401888ee8ec30 to your computer and use it in GitHub Desktop.
method to test private or protected methods of class
<?php
class PseudoUserTest extends PHPUnit_Framework_TestCase
{
public function invokeMethod(&$object, $methodName, $parameters = array())
{
$reflection = new ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment