@@ -790,4 +790,74 @@ function vendorAction(): void
790790
791791 expect ($ res )->toBe (['user ' => 'User ' ]);
792792 });
793+
794+ test ('checkConstantClosureParam validates arguments and respects config toggles and ignore tags ' , function () {
795+ $ valid = RuntimeTypeChecker ::checkConstantClosureParam (
796+ 'App\Config::Formatter ' ,
797+ 'id ' ,
798+ 10 ,
799+ 'positive-int ' ,
800+ __FILE__ ,
801+ 15
802+ );
803+ expect ($ valid )->toBe (10 );
804+
805+ $ invalid = RuntimeTypeChecker ::checkConstantClosureParam (
806+ 'App\Config::Formatter ' ,
807+ 'id ' ,
808+ -5 ,
809+ 'positive-int ' ,
810+ __FILE__ ,
811+ 15
812+ );
813+ expect ($ invalid )->toBeInstanceOf (ErrorMessage::class)
814+ ->and ($ invalid ->getMessage ())->toContain ('App\Config::Formatter(): Argument $id must be of type positive-int ' )
815+ ;
816+
817+ Config ::set (['params ' => false ]);
818+ expect (RuntimeTypeChecker ::checkConstantClosureParam ('App\Config::Formatter ' , 'id ' , -5 , 'positive-int ' ))->toBe (-5 );
819+
820+ Config ::set (['enabled ' => false , 'params ' => true ]);
821+ expect (RuntimeTypeChecker ::checkConstantClosureParam ('App\Config::Formatter ' , 'id ' , -5 , 'positive-int ' ))->toBe (-5 );
822+
823+ Config ::set (['enabled ' => true , 'params ' => true ]);
824+ $ ignored = RuntimeCheckerIgnoredCaller ::run (
825+ fn () => RuntimeTypeChecker ::checkConstantClosureParam ('App\Config::Formatter ' , 'id ' , -5 , 'positive-int ' )
826+ );
827+ expect ($ ignored )->toBe (-5 );
828+ });
829+
830+ test ('checkConstantClosureReturn validates return values and respects config toggles and ignore tags ' , function () {
831+ $ valid = RuntimeTypeChecker ::checkConstantClosureReturn (
832+ 'App\Config::Callback ' ,
833+ 42 ,
834+ 'int ' ,
835+ __FILE__ ,
836+ 25
837+ );
838+ expect ($ valid )->toBe (42 );
839+
840+ $ invalid = RuntimeTypeChecker ::checkConstantClosureReturn (
841+ 'App\Config::Callback ' ,
842+ 'not_an_int ' ,
843+ 'int ' ,
844+ __FILE__ ,
845+ 25
846+ );
847+ expect ($ invalid )->toBeInstanceOf (ErrorMessage::class)
848+ ->and ($ invalid ->getMessage ())->toContain ('App\Config::Callback(): Return value must be of type int, string \'not_an_int \' returned ' )
849+ ;
850+
851+ Config ::set (['returns ' => false ]);
852+ expect (RuntimeTypeChecker ::checkConstantClosureReturn ('App\Config::Callback ' , 'not_an_int ' , 'int ' ))->toBe ('not_an_int ' );
853+
854+ Config ::set (['enabled ' => false , 'returns ' => true ]);
855+ expect (RuntimeTypeChecker ::checkConstantClosureReturn ('App\Config::Callback ' , 'not_an_int ' , 'int ' ))->toBe ('not_an_int ' );
856+
857+ Config ::set (['enabled ' => true , 'returns ' => true ]);
858+ $ ignored = RuntimeCheckerIgnoredCaller ::run (
859+ fn () => RuntimeTypeChecker ::checkConstantClosureReturn ('App\Config::Callback ' , 'not_an_int ' , 'int ' )
860+ );
861+ expect ($ ignored )->toBe ('not_an_int ' );
862+ });
793863});
0 commit comments