allows to check toThrow against an exception instance

This commit is contained in:
Fabio Ivona
2023-05-01 21:42:47 +02:00
parent 2e25eb59b8
commit f8930d20ae
2 changed files with 24 additions and 2 deletions

View File

@ -2,6 +2,10 @@
use PHPUnit\Framework\ExpectationFailedException;
class CustomException extends Exception
{
}
test('passes', function () {
expect(function () {
throw new RuntimeException();
@ -33,6 +37,9 @@ test('passes', function () {
throw new RuntimeException('actual message');
})->toThrow(function (RuntimeException $e) {
}, 'actual message');
expect(function () {
throw new CustomException('foo');
})->toThrow(new CustomException('foo'));
});
test('failures 1', function () {
@ -79,6 +86,12 @@ test('failures 7', function () {
})->toThrow(RuntimeException::class, 'expected message');
})->throws(ExpectationFailedException::class);
test('failures 8', function () {
expect(function () {
throw new CustomException('actual message');
})->toThrow(new CustomException('expected message'));
})->throws(ExpectationFailedException::class);
test('failures with custom message', function () {
expect(function () {
throw new RuntimeException('actual message');