Eloquent\Phony\Spy\SpyVerifier::checkThrew PHP Метод

checkThrew() публичный Метод

Checks if an exception of the supplied type was thrown.
public checkThrew ( Eloquent\Phony\Matcher\Matcher | Exceptio\Exception | Erro\Error | string | null $type = null ) : Eloquent\Phony\Event\EventCollection | null
$type Eloquent\Phony\Matcher\Matcher | Exceptio\Exception | Erro\Error | string | null An exception to match, the type of exception, or null for any exception.
Результат Eloquent\Phony\Event\EventCollection | null The result.
    public function checkThrew($type = null)
    {
        $cardinality = $this->resetCardinality();
        $calls = $this->spy->allCalls();
        $matchingEvents = array();
        $totalCount = count($calls);
        $matchCount = 0;
        $isTypeSupported = false;
        if (!$type) {
            $isTypeSupported = true;
            foreach ($calls as $call) {
                if (!($responseEvent = $call->responseEvent())) {
                    continue;
                }
                list($exception) = $call->response();
                if ($exception) {
                    $matchingEvents[] = $responseEvent;
                    ++$matchCount;
                }
            }
        } elseif (is_string($type)) {
            $isTypeSupported = true;
            foreach ($calls as $call) {
                if (!($responseEvent = $call->responseEvent())) {
                    continue;
                }
                list($exception) = $call->response();
                if ($exception && is_a($exception, $type)) {
                    $matchingEvents[] = $responseEvent;
                    ++$matchCount;
                }
            }
        } elseif (is_object($type)) {
            if ($type instanceof Throwable || $type instanceof Exception) {
                $isTypeSupported = true;
                $type = $this->matcherFactory->equalTo($type, true);
            } elseif ($this->matcherFactory->isMatcher($type)) {
                $isTypeSupported = true;
                $type = $this->matcherFactory->adapt($type);
            }
            if ($isTypeSupported) {
                foreach ($calls as $call) {
                    if (!($responseEvent = $call->responseEvent())) {
                        continue;
                    }
                    list($exception) = $call->response();
                    if ($exception && $type->matches($exception)) {
                        $matchingEvents[] = $responseEvent;
                        ++$matchCount;
                    }
                }
            }
        }
        if (!$isTypeSupported) {
            throw new InvalidArgumentException(sprintf('Unable to match exceptions against %s.', $this->assertionRenderer->renderValue($type)));
        }
        if ($cardinality->matches($matchCount, $totalCount)) {
            return $this->assertionRecorder->createSuccess($matchingEvents);
        }
    }