public function verifyNegative($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 && null === $exception) {
throw new FailureException(sprintf('Expected to not throw any exceptions, but got %s.', $this->presenter->presentValue($exceptionThrown)));
}
if ($exceptionThrown && $exceptionThrown instanceof $exception) {
$invalidProperties = array();
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) {
$invalidProperties[] = sprintf(' `%s`=%s', $property->getName(), $this->presenter->presentValue($expected));
}
}
}
$withProperties = '';
if (count($invalidProperties) > 0) {
$withProperties = sprintf(' with' . PHP_EOL . '%s,' . PHP_EOL, implode(",\n", $invalidProperties));
}
throw new FailureException(sprintf('Expected to not throw %s exception%s but got it.', $this->presenter->presentValue($exception), $withProperties));
}
}