From 5895869e0149e0a2a39402b08cfbb6626662a9a9 Mon Sep 17 00:00:00 2001 From: Daniel Coulbourne Date: Mon, 12 Feb 2024 22:26:13 -0500 Subject: [PATCH] Fix the stupidest type check ever. --- src/Lifecycle/Guards.php | 4 ++-- tests/Feature/PendingEventChecksTest.php | 25 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Lifecycle/Guards.php b/src/Lifecycle/Guards.php index 0faac2ed..1a4447d0 100644 --- a/src/Lifecycle/Guards.php +++ b/src/Lifecycle/Guards.php @@ -67,8 +67,8 @@ protected function passesAuthorization(): bool if ($result instanceof Response) { return $result->authorize(); } - - if ($result instanceof bool) { + + if (is_bool($result)) { return $result; } diff --git a/tests/Feature/PendingEventChecksTest.php b/tests/Feature/PendingEventChecksTest.php index d4c557a9..f58e9e2f 100644 --- a/tests/Feature/PendingEventChecksTest.php +++ b/tests/Feature/PendingEventChecksTest.php @@ -22,6 +22,20 @@ $this->assertFalse($event->isAllowed()); }); +it('supports boolean authorization', function () { + $event = EventWithBooleanAuth::make([ + 'allowed' => true, + ]); + + $this->assertTrue($event->isAllowed()); + + $event = EventWithBooleanAuth::make([ + 'allowed' => false, + ]); + + $this->assertFalse($event->isAllowed()); +}); + it('can test validation on a pending event', function () { SpecialState::factory()->create([ 'name' => 'daniel', @@ -60,6 +74,17 @@ $this->assertFalse($event->isValid()); }); + +class EventWithBooleanAuth extends Event +{ + public bool $allowed; + + public function authorize() + { + return $this->allowed; + } +} + class EventWithMultipleStates extends Event { #[StateId(SpecialState::class)]