Eloquent\Phony\Call\CallVerifier::checkThrew PHP Method

checkThrew() public method

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.
return Eloquent\Phony\Event\EventCollection | null The result.
    public function checkThrew($type = null)
    {
        $cardinality = $this->resetCardinality()->assertSingular();
        if ($responseEvent = $this->call->responseEvent()) {
            list($exception) = $this->call->response();
        } else {
            $exception = null;
        }
        $isTypeSupported = false;
        if (!$type) {
            $isTypeSupported = true;
            list($matchCount, $matchingEvents) = $this->matchIf($responseEvent, $exception);
            if ($cardinality->matches($matchCount, 1)) {
                return $this->assertionRecorder->createSuccess($matchingEvents);
            }
        } elseif (is_string($type)) {
            $isTypeSupported = true;
            list($matchCount, $matchingEvents) = $this->matchIf($responseEvent, is_a($exception, $type));
            if ($cardinality->matches($matchCount, 1)) {
                return $this->assertionRecorder->createSuccess($matchingEvents);
            }
        } 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) {
                list($matchCount, $matchingEvents) = $this->matchIf($responseEvent, $exception && $type->matches($exception));
                if ($cardinality->matches($matchCount, 1)) {
                    return $this->assertionRecorder->createSuccess($matchingEvents);
                }
            }
        }
        if (!$isTypeSupported) {
            throw new InvalidArgumentException(sprintf('Unable to match exceptions against %s.', $this->assertionRenderer->renderValue($type)));
        }
    }