public static function callMethod($obj, $class, $method, $args, $check_mock = false)
{
if (!$class) {
$class = get_class($obj);
}
if ($check_mock && isset(self::$mocks[$class][$method])) {
if (self::$debug) {
self::debug("Intercepting call to {$class}->{$method}");
}
return (new SoftMocksFunctionCreator())->run($obj, $class, $args, self::$mocks[$class][$method]);
}
try {
$Rm = new \ReflectionMethod($class, $method);
$Rm->setAccessible(true);
$decl_class = $Rm->getDeclaringClass()->getName();
if ($check_mock && isset(self::$mocks[$decl_class][$method])) {
if (self::$debug) {
self::debug("Intercepting call to {$class}->{$method}");
}
return (new SoftMocksFunctionCreator())->run($obj, $class, $args, self::$mocks[$decl_class][$method]);
}
} catch (\ReflectionException $e) {
if (method_exists($obj, '__call')) {
$Rm = new \ReflectionMethod($obj, '__call');
$Rm->setAccessible(true);
return $Rm->invokeArgs($obj, [$method, $args]);
}
return call_user_func_array([$obj, $method], $args);
// give up, got some weird shit
}
return $Rm->invokeArgs($obj, $args);
}