@param \PHPUnit_Framework_MockObject_Invocation $invocation

@return mixed
@throws \Exception
346971
public function invoke(\PHPUnit_Framework_MockObject_Invocation $invocation)
    {
        $exception      = null;
        $hasReturnValue = false;

        $returnValue = next::caller();

        foreach ($this->matchers as $match) {
            try {
                if ($match->matches($invocation)) {
                    $value = $match->invoked($invocation);

                    if (!$hasReturnValue) {
                        $returnValue    = $value;
                        $hasReturnValue = true;
                    }
                }
            } catch (\Exception $e) {
                $exception = $e;
            }
        }

        if ($exception !== null) {
            throw $exception;
        }

        return $returnValue;
    }
823785
public static function get($object)
    {
        $cid = MANAPHP_COROUTINE ? \Swoole\Coroutine::getuid() : -1;

        $oid = spl_object_id($object);
        if (!isset(self::$_contexts[$cid][$oid])) {
            if (!$context_class = $object->getContextClass()) {
                throw new Exception(['`:context` context class is not exists', 'context' => get_class($object) . 'Context']);
            }
            return self::$_contexts[$cid][$oid] = new $context_class;
        } else {
            return self::$_contexts[$cid][$oid];
        }
    }
411883
public function invoke(MethodInvocation $invocation)
    {
        /** @var \Ytake\LaravelAspect\Annotation\LogExceptions $annotation */
        $annotation = $invocation->getMethod()->getAnnotation($this->annotation);
        try {
            $result = $invocation->proceed();
        } catch (\Exception $exception) {
            if ($exception instanceof $annotation->expect) {
                $logFormat = $this->logFormatter($annotation, $invocation);
                $logger = static::$logger;
                /** Monolog\Logger */
                $logFormat['context']['code'] = $exception->getCode();
                $logFormat['context']['error_message'] = $exception->getMessage();
                if ($logger instanceof LogManager) {
                    if (!is_null($annotation->driver)) {
                        $logger = $logger->driver($annotation->driver);
                    }
                    $logger->addRecord($logFormat['level'], $logFormat['message'], $logFormat['context']);
                }
            }
            throw $exception;
        }

        // @codeCoverageIgnoreStart
        return $result;
        // @codeCoverageIgnoreEnd
    }
1317197
public function getInvocationMessage()
    {
        if ($this->invocationMessage === null) {
            // try to create one
            if ($this->registration === null) {
                throw new \Exception('You must set the registration prior to calling getInvocationMessage');
            }

            if ($this->callMessage === null) {
                throw new \Exception('You must set the CallMessage prior to calling getInvocationMessage');
            }

            $invocationMessage = InvocationMessage::createMessageFrom($this->getCallMessage(), $this->getRegistration());

            $invocationMessage->setRequestId($this->getInvocationRequestId());

            $details = [];

            if ($this->getRegistration()->getDiscloseCaller() === true && $this->getCallerSession()->getAuthenticationDetails()) {
                $authenticationDetails = $this->getCallerSession()->getAuthenticationDetails();
                $details               = [
                    'caller'     => $this->getCallerSession()->getSessionId(),
                    'authid'     => $authenticationDetails->getAuthId(),
                    'authrole'   => $authenticationDetails->getAuthRole(),
                    'authroles'  => $authenticationDetails->getAuthRoles(),
                    'authmethod' => $authenticationDetails->getAuthMethod(),
                ];

                if ($authenticationDetails->getAuthExtra() !== null) {
                    $details['_thruway_authextra'] = $authenticationDetails->getAuthExtra();
                }
            }

            // TODO: check to see if callee supports progressive call
            $callOptions   = $this->getCallMessage()->getOptions();
            $isProgressive = false;
            if (is_object($callOptions) && isset($callOptions->receive_progress) && $callOptions->receive_progress) {
                $details       = array_merge($details, ['receive_progress' => true]);
                $isProgressive = true;
            }

            // if nothing was added to details - change ot stdClass so it will serialize correctly
            if (count($details) === 0) {
                $details = new \stdClass();
            }
            $invocationMessage->setDetails($details);

            $this->setIsProgressive($isProgressive);

            $this->setInvocationMessage($invocationMessage);
        }

        return $this->invocationMessage;
    }
1183416
public function invokeWith($arguments = [])
    {
        if (!$arguments instanceof Arguments) {
            $arguments = new Arguments($arguments);
        }

        return $this->callTraitMethod->invoke(
            $this->mock,
            $this->traitName,
            $this->name,
            $arguments
        );
    }
912609
private function preBuild(AbstractInvoke $invoke): AbstractInvoke
    {
        $result = $this->preBuild->handle(new BuilderContainer($this, $invoke));

        if ($result instanceof BuilderContainer) {
            return $result->getInvoke();
        }

        throw new \RuntimeException();
    }
597988
public function alterCreate(MethodInvocation $invocation)
    {
        $helper = $invocation->getThis();
        list($model, $options) = array_pad($invocation->getArguments(), 2, null);
        $options = (array)$options;
        $bootstrap = isset($options['bootstrap']) ? (bool)$options['bootstrap'] : true;

        if ($bootstrap) {
            $this->_addTemplates($helper);
        }

        if (isset($options['bootstrap'])) {
            unset($options['bootstrap']);
        }

        $this->setProperty($invocation, 'arguments', [$model, $options]);

        return $invocation->proceed();
    }
1337164
private function handleCallUnit(Invoke\Invoke $unit): Result\AbstractResult
    {
        try {
            list($class, $method) = $this->getClassAndMethod($unit->getRawMethod());
            $result = $this->invoker->invoke($this->handlers[$class], $method, $unit->getRawParams());
        } catch (JsonRpcException $exception) {
            return new Result\Error($unit->getRawId(), $exception);
        }

        return new Result\Result($unit->getRawId(), $result);
    }
646392
protected function detectCacheKeys(
        MethodInvocation $invocation,
        Annotation $annotation,
        array $keys
    ): array {
        $arguments = $invocation->getArguments();
        foreach ($invocation->getMethod()->getParameters() as $parameter) {
            // exclude object
            if (in_array('#' . $parameter->name, $annotation->key)) {
                if (isset($arguments[$parameter->getPosition()])) {
                    if (!is_object($arguments[$parameter->getPosition()])) {
                        $keys[] = $arguments[$parameter->getPosition()];
                    }
                }
                if (!isset($arguments[$parameter->getPosition()])) {
                    $keys[] = $parameter->getDefaultValue();
                }
            }
        }

        return $keys;
    }
674000
public function method($constraint)
    {
        $any = new \PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
        $expects = $this->expects($any);
        return call_user_func_array(array($expects, 'method'), func_get_args());
    }
14252
@Override
    public void interceptSetupMethod(IMethodInvocation invocation) throws Throwable {
        log.fine("before " + invocation.getFeature().getFeatureMethod().getReflection().getName());
        getTestRunner().before(invocation.getTarget(), invocation.getFeature().getFeatureMethod().getReflection(),
            new InvocationExecutor(invocation));
    }
300759
public function setInvocation(Invocation $invocation)
    {
        $this->invocation = $invocation;

        $this->setAttachments($invocation->getAttachments());
    }
830092
protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool
    {
        if ($function instanceof \ReflectionFunction) {
            return !$invocation->isMethod();
        }

        try {
            $reflection = $this->classReflection($invocation->getClass());
        } catch (LocatorException $e) {
            return false;
        }

        /**
         * @var \ReflectionMethod $function
         */
        $target = $function->getDeclaringClass();

        if ($target->isTrait()) {
            //Let's compare traits
            return in_array($target->getName(), $this->fetchTraits($invocation->getClass()));
        }

        return $reflection->getName() == $target->getName() || $reflection->isSubclassOf($target);
    }
193561
private function preProcess(AbstractInvoke $invoke): AbstractInvoke
    {
        $result = $this->preProcess->handle(new ProcessorContainer($this, $invoke));

        if ($result instanceof ProcessorContainer) {
            return $result->getInvoke();
        }

        throw new \RuntimeException();
    }
887166
public void copyFrom(Invocation invocation)
  {
    _classLoader = invocation._classLoader;
    
    _rawHost = invocation._rawHost;
    _rawURI = invocation._rawURI;

    _hostName = invocation._hostName;
    _port = invocation._port;
    _uri = invocation._uri;
    
    _depend = invocation._depend;
    
    _queryString = invocation._queryString;
  }
494181
private function getMockCallback(
        string $class,
        int $callIndex,
        Call $call,
        MockObject $mock
    ): \Closure {
        return function () use ($class, $callIndex, $call, $mock) {
            if ($call->hasWith()) {
                $this->compareArguments($class, $call->getMethod(), $callIndex, $call->getWith(), func_get_args());
            }

            if (null !== $exception = $call->getException()) {
                throw $exception;
            }

            if ($call->hasReturnSelf()) {
                return $mock;
            }

            if ($call->hasReturn()) {
                return $call->getReturn();
            }

            if ($call->hasReturnCallback()) {
                $callback = $call->getReturnCallback();

                return $callback(...func_get_args());
            }
        };
    }
668563
public function proxy(Invoker $invoker)
    {
        $interface = $invoker->getInterface();

        $className = $this->generateClassName($interface);

        $code = $this->populateStub($this->getStub(), $className, $interface);

        $this->load($className, $code);

        return $this->createProxyInstance($className, $interface, $invoker);
    }