diff --git a/src/PendingObjects/TestCall.php b/src/PendingObjects/TestCall.php index 41d85826..4ad60bde 100644 --- a/src/PendingObjects/TestCall.php +++ b/src/PendingObjects/TestCall.php @@ -61,9 +61,13 @@ final class TestCall */ public function throws(string $exceptionClass, string $exceptionMessage = null): TestCall { - $this->testCaseFactory - ->proxies - ->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]); + if (class_exists($exceptionClass)) { + $this->testCaseFactory + ->proxies + ->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]); + } else { + $exceptionMessage = $exceptionClass; + } if (is_string($exceptionMessage)) { $this->testCaseFactory diff --git a/tests/Features/Exceptions.php b/tests/Features/Exceptions.php index 5e7e51a9..37eaaeb9 100644 --- a/tests/Features/Exceptions.php +++ b/tests/Features/Exceptions.php @@ -13,3 +13,7 @@ it('catch exceptions', function () { it('catch exceptions and messages', function () { throw new Exception('Something bad happened'); })->throws(Exception::class, 'Something bad happened'); + +it('can just define the message', function () { + throw new Exception('Something bad happened'); +})->throws('Something bad happened');