public static function assertException($runnable, $class, $message)
{
try {
$runnable();
self::fail('No exception thrown');
} catch (Exception $e) {
if ($e instanceof $class) {
$messageConstraint = new PHPUnit_Framework_Constraint_StringContains($message, true);
if (!$messageConstraint->evaluate($e->getMessage())) {
throw $messageConstraint->fail($e->getMessage(), PHP_EOL . $e->getTraceAsString());
}
self::assertTrue(true);
// update assertion counter
self::assertTrue(true);
// update assertion counter
} else {
if ($e instanceof PHPUnit_Framework_AssertionFailedError && $e->getMessage() === 'No exception thrown') {
throw $e;
}
$constraint = new PHPUnit_Framework_Constraint_IsInstanceOf($class);
throw $constraint->fail($e, 'Expected ' . $class . ' but ' . get_class($e) . ' with message "' . $e->getMessage() . '"' . PHP_EOL . $e->getTraceAsString());
}
}
}