mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 18:27:23 +01:00
refactor: throwsIf method
This commit is contained in:
@ -81,17 +81,17 @@ final class TestCall
|
|||||||
/**
|
/**
|
||||||
* Asserts that the test throws the given `$exceptionClass` when called if the given condition is true.
|
* 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
|
public function throwsIf($condition, string $exception, string $exceptionMessage = null): TestCall
|
||||||
{
|
{
|
||||||
$condition = is_callable($condition)
|
$condition = is_callable($condition)
|
||||||
? $condition
|
? $condition
|
||||||
: Closure::fromCallable(function () use ($condition): bool {
|
: static function () use ($condition): mixed {
|
||||||
return (bool) $condition;
|
return $condition;
|
||||||
});
|
};
|
||||||
|
|
||||||
if ($condition() === true) {
|
if ($condition()) {
|
||||||
return $this->throws($exception, $exceptionMessage);
|
return $this->throws($exception, $exceptionMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -695,5 +695,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 4 incompleted, 9 skipped, 454 passed
|
Tests: 4 incompleted, 9 skipped, 459 passed
|
||||||
|
|
||||||
Reference in New Issue
Block a user