Skip to content

Commit

Permalink
Fix the stupidest type check ever.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielCoulbourne committed Feb 13, 2024
1 parent 3b782be commit 5895869
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Lifecycle/Guards.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/PendingEventChecksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 5895869

Please sign in to comment.