From 4daf7ee4ab4004e51d385a0ccc1d33efe6db0027 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 24 Sep 2021 21:15:31 +0100 Subject: [PATCH] refactor: throwsIf method --- src/PendingObjects/TestCall.php | 10 +++++----- tests/.snapshots/success.txt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PendingObjects/TestCall.php b/src/PendingObjects/TestCall.php index f8ada58d..287ca7a9 100644 --- a/src/PendingObjects/TestCall.php +++ b/src/PendingObjects/TestCall.php @@ -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); } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index cac11672..40ab0a49 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -695,5 +695,5 @@ ✓ it is a test ✓ it uses correct parent class - Tests: 4 incompleted, 9 skipped, 454 passed + Tests: 4 incompleted, 9 skipped, 459 passed \ No newline at end of file