diff --git a/src/PendingObjects/TestCall.php b/src/PendingObjects/TestCall.php index 41d85826..81349be1 100644 --- a/src/PendingObjects/TestCall.php +++ b/src/PendingObjects/TestCall.php @@ -59,11 +59,15 @@ final class TestCall /** * Asserts that the test throws the given `$exceptionClass` when called. */ - public function throws(string $exceptionClass, string $exceptionMessage = null): TestCall + public function throws(string $exception, string $exceptionMessage = null): TestCall { - $this->testCaseFactory - ->proxies - ->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]); + if (class_exists($exception)) { + $this->testCaseFactory + ->proxies + ->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exception]); + } else { + $exceptionMessage = $exception; + } 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');