feat: throwsUnless method

This commit is contained in:
Thai Nguyen Hung
2023-08-24 09:28:47 +07:00
parent 14859a4c89
commit 6c3d8829ce
2 changed files with 52 additions and 0 deletions

View File

@ -104,6 +104,24 @@ final class TestCall
return $this;
}
/**
* Asserts that the test throws the given `$exceptionClass` when called if the given condition is falsy.
*
* @param (callable(): bool)|bool $condition
*/
public function throwsUnless(callable|bool $condition, string|int $exception, string $exceptionMessage = null, int $exceptionCode = null): self
{
$condition = is_callable($condition)
? $condition
: static fn (): bool => $condition;
if (! $condition()) {
return $this->throws($exception, $exceptionMessage, $exceptionCode);
}
return $this;
}
/**
* Runs the current test multiple times with
* each item of the given `iterable`.