From 5895869e0149e0a2a39402b08cfbb6626662a9a9 Mon Sep 17 00:00:00 2001 From: Daniel Coulbourne Date: Mon, 12 Feb 2024 22:26:13 -0500 Subject: [PATCH 1/2] 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)] From b9b34d1633be99bc84c2c89ec9b2239608e7303a Mon Sep 17 00:00:00 2001 From: DanielCoulbourne Date: Tue, 13 Feb 2024 03:26:42 +0000 Subject: [PATCH 2/2] Fix styling --- src/Lifecycle/Guards.php | 2 +- tests/Feature/PendingEventChecksTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Lifecycle/Guards.php b/src/Lifecycle/Guards.php index 1a4447d0..1273a4d2 100644 --- a/src/Lifecycle/Guards.php +++ b/src/Lifecycle/Guards.php @@ -67,7 +67,7 @@ protected function passesAuthorization(): bool if ($result instanceof Response) { return $result->authorize(); } - + if (is_bool($result)) { return $result; } diff --git a/tests/Feature/PendingEventChecksTest.php b/tests/Feature/PendingEventChecksTest.php index f58e9e2f..494bd1d4 100644 --- a/tests/Feature/PendingEventChecksTest.php +++ b/tests/Feature/PendingEventChecksTest.php @@ -29,7 +29,7 @@ $this->assertTrue($event->isAllowed()); - $event = EventWithBooleanAuth::make([ + $event = EventWithBooleanAuth::make([ 'allowed' => false, ]); @@ -74,7 +74,6 @@ $this->assertFalse($event->isValid()); }); - class EventWithBooleanAuth extends Event { public bool $allowed;