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