Skip to content

Commit

Permalink
test type-narrowing with Object|null (laravel#53154)
Browse files Browse the repository at this point in the history
  • Loading branch information
crishoj committed Oct 14, 2024
1 parent b425abe commit a07b390
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions types/Support/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function testThrowIf(float|int $foo): void
assertType('int', $foo);
throw_if($foo == false);
assertType('int<min, -1>|int<1, max>', $foo);
}

function testThrowIfWithFalseyValue(): void
{
assertType('null', throw_if(null, Exception::class));
assertType('string', throw_if('', Exception::class));
assertType('never', throw_if('foo', Exception::class));
Expand All @@ -64,6 +68,13 @@ function testThrowUnless(float|int $foo): void
assertType('int', $foo);
throw_unless($foo == false);
assertType('0', $foo);
}

function testThrowUnlessWithFalseyValue(Carbon\Carbon|null $date): void
{
throw_unless($date);
assertType('Carbon', $date);

assertType('never', throw_unless(null, Exception::class));
assertType('never', throw_unless('', Exception::class));
assertType('string', throw_unless('foo', Exception::class));
Expand Down

0 comments on commit a07b390

Please sign in to comment.