protected function stub(MethodInvocation $invocation, $params) { $name = $invocation->getMethod(); $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, $invocation->getArguments()); }