File tree Expand file tree Collapse file tree 3 files changed +16
-15
lines changed
Expand file tree Collapse file tree 3 files changed +16
-15
lines changed Original file line number Diff line number Diff line change 99use ReflectionFunction ;
1010use ReflectionMethod ;
1111use ReflectionNamedType ;
12- use Webmozart \Assert \Assert ;
1312
14- use function explode ;
1513use function is_object ;
1614use function sprintf ;
17- use function str_contains ;
1815
1916final class Filter
2017{
@@ -25,14 +22,7 @@ public static function boolean(callable $filter): void
2522 } elseif (is_object ($ filter )) {
2623 $ reflection = new ReflectionMethod ($ filter , '__invoke ' );
2724 } else {
28- Assert::string ($ filter );
29-
30- if (! str_contains ($ filter , ':: ' )) {
31- $ reflection = new ReflectionFunction ($ filter );
32- } else {
33- [, $ method ] = explode (':: ' , $ filter );
34- $ reflection = new ReflectionMethod ($ filter , $ method );
35- }
25+ throw new InvalidArgumentException ('Expected Closure or invokable object, string given ' );
3626 }
3727
3828 $ returnType = $ reflection ->getReturnType ();
Original file line number Diff line number Diff line change @@ -68,8 +68,8 @@ public function getResults(): array
6868 // ensure transform property is set early ->withTransform() method
6969 Assert::isCallable ($ this ->transform );
7070
71- $ count = 0 ;
72- $ collectedData = [];
71+ $ count = 0 ;
72+ $ collectedData = [];
7373
7474 if (is_callable ($ this ->when )) {
7575 // filter must be a callable with bool return type
Original file line number Diff line number Diff line change @@ -23,6 +23,17 @@ public function __invoke(int $datum): bool
2323 $ this ->assertTrue (AtLeast::once ($ data , $ filter ));
2424 }
2525
26+ public function testOnceWithStringFilter (): void
27+ {
28+ $ this ->expectException (InvalidArgumentException::class);
29+ $ this ->expectExceptionMessage ('Expected Closure or invokable object, string given ' );
30+
31+ $ data = [1 , 'f ' ];
32+ $ filter = 'is_string ' ;
33+
34+ AtLeast::once ($ data , $ filter );
35+ }
36+
2637 public function testWithoutReturnTypeCallable (): void
2738 {
2839 $ this ->expectException (InvalidArgumentException::class);
@@ -39,7 +50,7 @@ public function __invoke(int $datum)
3950 };
4051 // phpcs:enable
4152
42- $ this -> assertTrue ( AtLeast::once ($ data , $ filter) );
53+ AtLeast::once ($ data , $ filter );
4354 }
4455
4556 public function testWithNonBoolReturnTypeCallable (): void
@@ -55,6 +66,6 @@ public function __invoke(int $datum): string
5566 }
5667 };
5768
58- $ this -> assertTrue ( AtLeast::once ($ data , $ filter) );
69+ AtLeast::once ($ data , $ filter );
5970 }
6071}
You can’t perform that action at this time.
0 commit comments