File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -60,11 +60,19 @@ public static function boolean(callable $filter): void
6060 }
6161
6262 $ returnTypeName = $ returnType ->getName ();
63+
6364 if ($ returnTypeName !== 'bool ' ) {
6465 throw new InvalidArgumentException (sprintf (
6566 self ::MESSAGE ,
6667 $ returnTypeName
6768 ));
6869 }
70+
71+ if ($ returnType ->allowsNull ()) {
72+ throw new InvalidArgumentException (sprintf (
73+ self ::MESSAGE ,
74+ '? ' . $ returnTypeName
75+ ));
76+ }
6977 }
7078}
Original file line number Diff line number Diff line change @@ -69,6 +69,22 @@ public function __invoke(int $datum): string
6969 AtLeast::once ($ data , $ filter );
7070 }
7171
72+ public function testWithNullableReturnTypeCallable (): void
73+ {
74+ $ this ->expectException (InvalidArgumentException::class);
75+ $ this ->expectExceptionMessage ('Expected a bool return type on callable filter, ?bool given ' );
76+
77+ $ data = [1 , 2 , 3 ];
78+ $ filter = new class {
79+ public function __invoke (int $ datum ): ?bool
80+ {
81+ return true ;
82+ }
83+ };
84+
85+ AtLeast::once ($ data , $ filter );
86+ }
87+
7288 public function testWithUnionReturnTypeCallable (): void
7389 {
7490 $ this ->expectException (InvalidArgumentException::class);
You can’t perform that action at this time.
0 commit comments