Skip to content

Commit

Permalink
Merge pull request #59 from hirethunk/daniel/fix-stupid-boolean-check
Browse files Browse the repository at this point in the history
Fix the stupidest type check ever.
  • Loading branch information
DanielCoulbourne authored Feb 13, 2024
2 parents 3b782be + b9b34d1 commit eb8edca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Lifecycle/Guards.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function passesAuthorization(): bool
return $result->authorize();
}

if ($result instanceof bool) {
if (is_bool($result)) {
return $result;
}

Expand Down
24 changes: 24 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,16 @@
$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 eb8edca

Please sign in to comment.