Бывает, не хочется портить API ради тестирования, но нужно как-то добраться до private метода.
function callPrivateMethod($object, $method, $args)
{
$classReflection = new \ReflectionClass(get_class($object));
$methodReflection = $classReflection->getMethod($method);
$methodReflection->setAccessible(true);
$result = $methodReflection->invokeArgs($object, $args);
$methodReflection->setAccessible(false);
return $result;
}
$myObject = new MyClass();
callPrivateMethod($myObject, 'hello', ['world']);