Allows you to just specify an exception message when calling throws.

This commit is contained in:
luke
2021-07-08 18:32:02 +01:00
parent 7d6a86adc7
commit 99ea9f42e5
2 changed files with 11 additions and 3 deletions

View File

@ -61,9 +61,13 @@ final class TestCall
*/ */
public function throws(string $exceptionClass, string $exceptionMessage = null): TestCall public function throws(string $exceptionClass, string $exceptionMessage = null): TestCall
{ {
$this->testCaseFactory if (class_exists($exceptionClass)) {
->proxies $this->testCaseFactory
->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]); ->proxies
->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]);
} else {
$exceptionMessage = $exceptionClass;
}
if (is_string($exceptionMessage)) { if (is_string($exceptionMessage)) {
$this->testCaseFactory $this->testCaseFactory

View File

@ -13,3 +13,7 @@ it('catch exceptions', function () {
it('catch exceptions and messages', function () { it('catch exceptions and messages', function () {
throw new Exception('Something bad happened'); throw new Exception('Something bad happened');
})->throws(Exception::class, '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');