|
41 | 41 | }));
|
42 | 42 | assertType('Illuminate\Support\HigherOrderTapProxy', tap(new User()));
|
43 | 43 |
|
44 |
| -function testThrowIf(float|int $foo): void |
| 44 | +function testThrowIf(float|int $foo, DateTime $bar = null): void |
45 | 45 | {
|
46 | 46 | assertType('never', throw_if(true, Exception::class));
|
47 | 47 | assertType('bool', throw_if(false, Exception::class));
|
48 | 48 | assertType('false', throw_if(empty($foo)));
|
| 49 | + throw_if(is_float($foo)); |
| 50 | + assertType('int', $foo); |
| 51 | + throw_if($foo == false); |
| 52 | + assertType('int<min, -1>|int<1, max>', $foo); |
| 53 | + |
| 54 | + // Truthy/falsey argument |
| 55 | + throw_if($bar); |
| 56 | + assertType('null', $bar); |
49 | 57 | assertType('null', throw_if(null, Exception::class));
|
50 | 58 | assertType('string', throw_if('', Exception::class));
|
51 | 59 | assertType('never', throw_if('foo', Exception::class));
|
52 | 60 | }
|
53 | 61 |
|
54 |
| -function testThrowUnless(float|int $foo): void |
| 62 | +function testThrowUnless(float|int $foo, DateTime $bar = null): void |
55 | 63 | {
|
56 | 64 | assertType('bool', throw_unless(true, Exception::class));
|
57 | 65 | assertType('never', throw_unless(false, Exception::class));
|
58 | 66 | assertType('true', throw_unless(empty($foo)));
|
59 | 67 | throw_unless(is_int($foo));
|
| 68 | + assertType('int', $foo); |
| 69 | + throw_unless($foo == false); |
| 70 | + assertType('0', $foo); |
| 71 | + throw_unless($bar instanceof DateTime); |
| 72 | + assertType('DateTime', $bar); |
| 73 | + |
| 74 | + // Truthy/falsey argument |
60 | 75 | assertType('never', throw_unless(null, Exception::class));
|
61 | 76 | assertType('never', throw_unless('', Exception::class));
|
62 | 77 | assertType('string', throw_unless('foo', Exception::class));
|
|
0 commit comments