protected function stubMagicMethod(MethodInvocation $invocation, $params) { $args = $invocation->getArguments(); $name = array_shift($args); $replacedMethod = $params[$name]; $replacedMethod = $this->turnToClosure($replacedMethod); if ($invocation->isStatic()) { \Closure::bind($replacedMethod, null, $invocation->getThis()); } else { $replacedMethod = $replacedMethod->bindTo($invocation->getThis(), get_class($invocation->getThis())); } return call_user_func_array($replacedMethod, $args); }