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)));
}
}