refactor: throwsIf method

This commit is contained in:
Nuno Maduro
2021-09-24 21:15:31 +01:00
parent d60f320382
commit 4daf7ee4ab
2 changed files with 6 additions and 6 deletions

View File

@ -81,17 +81,17 @@ final class TestCall
/**
* Asserts that the test throws the given `$exceptionClass` when called if the given condition is true.
*
* @param Closure|bool|int $condition
* @param (callable(): bool)|bool $condition
*/
public function throwsIf($condition, string $exception, string $exceptionMessage = null): TestCall
{
$condition = is_callable($condition)
? $condition
: Closure::fromCallable(function () use ($condition): bool {
return (bool) $condition;
});
: static function () use ($condition): mixed {
return $condition;
};
if ($condition() === true) {
if ($condition()) {
return $this->throws($exception, $exceptionMessage);
}