public function checkReturned($value = null)
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = array();
$totalCount = count($calls);
$matchCount = 0;
if (0 === func_num_args()) {
foreach ($calls as $call) {
if (!($responseEvent = $call->responseEvent())) {
continue;
}
list($exception) = $call->response();
if (!$exception) {
$matchingEvents[] = $responseEvent;
++$matchCount;
}
}
} else {
$value = $this->matcherFactory->adapt($value);
foreach ($calls as $call) {
if (!($responseEvent = $call->responseEvent())) {
continue;
}
list($exception, $returnValue) = $call->response();
if (!$exception && $value->matches($returnValue)) {
$matchingEvents[] = $responseEvent;
++$matchCount;
}
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
}