public function verifyPositive($callable, array $arguments, $exception = null)
{
$exceptionThrown = null;
try {
call_user_func_array($callable, $arguments);
} catch (\Exception $e) {
$exceptionThrown = $e;
} catch (\Throwable $e) {
$exceptionThrown = $e;
}
if (!$exceptionThrown) {
throw new FailureException('Expected to get exception / throwable, none got.');
}
if (null === $exception) {
return;
}
if (!$exceptionThrown instanceof $exception) {
$format = 'Expected exception of class %s, but got %s.';
if ($exceptionThrown instanceof \Error) {
$format = 'Expected exception of class %s, but got %s with the message: "%s"';
}
throw new FailureException(sprintf($format, $this->presenter->presentValue($exception), $this->presenter->presentValue($exceptionThrown), $exceptionThrown->getMessage()));
}
if (is_object($exception)) {
$exceptionRefl = $this->factory->create($exception);
foreach ($exceptionRefl->getProperties() as $property) {
if (in_array($property->getName(), self::$ignoredProperties, true)) {
continue;
}
$property->setAccessible(true);
$expected = $property->getValue($exception);
$actual = $property->getValue($exceptionThrown);
if (null !== $expected && $actual !== $expected) {
throw new NotEqualException(sprintf('Expected exception `%s` to be %s, but it is %s.', $property->getName(), $this->presenter->presentValue($expected), $this->presenter->presentValue($actual)), $expected, $actual);
}
}
}
}