src/Assert.php
public static function throws(callable $callback, string $expectedException = '', string $message = '')
    {
        self::$count += 1;

        $exception = null;
        try {
            $callback();
        } catch (\Error $exception) {

        } catch (\Exception $exception) {

        }

        if ($exception === null) {
            throw new AssertionError($message ?: 'No exception thrown');
        } elseif ($expectedException && !is_a($exception, $expectedException)) {
            throw new AssertionError(
                $message ?: sprintf(
                    'Expected %s got %s',
                    $expectedException,
                    get_class($exception)
                )
            );
        }
    }
public static function throws(callable $callback, string $expectedException = '', string $message = '')
    {
        self::$count += 1;

        $exception = null;
        try {
            $callback();
        } catch (\Error $exception) {

        } catch (\Exception $exception) {

        }

        if ($exception === null) {
            throw new AssertionError($message ?: 'No exception thrown');
        } elseif ($expectedException && !is_a($exception, $expectedException)) {
            throw new AssertionError(
                $message ?: sprintf(
                    'Expected %s got %s',
                    $expectedException,
                    get_class($exception)
                )
            );
        }
    }
public static function throws ( callable $ callback , string $ expectedException = '' , string $ message = '' ) { self :: $ count += 1 ; $ exception = null ; try { $ callback ( ) ; } catch ( \ Error $ exception ) { } catch ( \ Exception $ exception ) { } if ( $ exception === null ) { throw new AssertionError ( $ message ? : 'No exception thrown' ) ; } elseif ( $ expectedException && ! is_a ( $ exception , $ expectedException ) ) { throw new AssertionError ( $ message ? : sprintf ( 'Expected %s got %s' , $ expectedException , get_class ( $ exception ) ) ) ; } }
Test if the callback throws an exception

@example

test_flight_throws(function() { throw new \Exception(); });
test_flight_throws(function() { throw new \RuntimeException(); }, 'RuntimeException');

$didThrow = false;
try {
test_flight_throws(function() { return true; });
} catch (\Cundd\TestFlight\Exception\AssertionError $e) {
$didThrow = true;
}
assert($didThrow);

$didThrowWrongException = false;
$exceptionMessage = '';
try {
test_flight_throws(function() { throw new \LogicException(); }, 'RuntimeException');
} catch (\Cundd\TestFlight\Exception\AssertionError $e) {
$didThrowWrongException = true;
$exceptionMessage = $e->getMessage();
}
assert($didThrowWrongException, 'No exception thrown');
assert('Expected RuntimeException got LogicException' === $exceptionMessage, 'Exception message does not match');

@param callable $callback
@param string   $expectedException
@param string   $message
@throws AssertionError
Test if the callback throws an exception