@@ -587,4 +587,78 @@ public function testWildcardRoute(): void
587587 $ _SERVER ['REQUEST_METHOD ' ] = $ method ;
588588 $ _SERVER ['REQUEST_URI ' ] = $ uri ;
589589 }
590+
591+ public function testAnyRoute (): void
592+ {
593+ Http::reset ();
594+
595+ $ method = $ _SERVER ['REQUEST_METHOD ' ] ?? null ;
596+ $ uri = $ _SERVER ['REQUEST_URI ' ] ?? null ;
597+
598+ $ methods = ['GET ' , 'POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' ];
599+ $ responseTexts = [];
600+
601+ // Create a route that matches any method for a specific path
602+ Http::any ('/specific-path ' )
603+ ->inject ('response ' )
604+ ->action (function ($ response ) {
605+ $ response ->send ('ANY METHOD ROUTE ' );
606+ });
607+
608+ // Create method-specific routes for a different path
609+ Http::get ('/method-specific ' )
610+ ->inject ('response ' )
611+ ->action (function ($ response ) {
612+ $ response ->send ('GET ROUTE ' );
613+ });
614+
615+ Http::post ('/method-specific ' )
616+ ->inject ('response ' )
617+ ->action (function ($ response ) {
618+ $ response ->send ('POST ROUTE ' );
619+ });
620+
621+ // Test with different methods on the 'any' route
622+ foreach ($ methods as $ httpMethod ) {
623+ $ _SERVER ['REQUEST_METHOD ' ] = $ httpMethod ;
624+ $ _SERVER ['REQUEST_URI ' ] = '/specific-path ' ;
625+
626+ \ob_start ();
627+ @$ this ->http ->run (new Request (), new Response (), '1 ' );
628+ $ result = \ob_get_contents ();
629+ \ob_end_clean ();
630+
631+ $ responseTexts [$ httpMethod ] = $ result ;
632+ }
633+
634+ // Check that all HTTP methods match the 'any' route
635+ foreach ($ methods as $ httpMethod ) {
636+ $ this ->assertEquals ('ANY METHOD ROUTE ' , $ responseTexts [$ httpMethod ], "Method $ httpMethod failed to match the 'any' route " );
637+ }
638+
639+ // Test that method-specific routes work as expected
640+ $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
641+ $ _SERVER ['REQUEST_URI ' ] = '/method-specific ' ;
642+
643+ \ob_start ();
644+ @$ this ->http ->run (new Request (), new Response (), '1 ' );
645+ $ result = \ob_get_contents ();
646+ \ob_end_clean ();
647+
648+ $ this ->assertEquals ('GET ROUTE ' , $ result , "Method-specific GET route did not match " );
649+
650+ $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
651+ $ _SERVER ['REQUEST_URI ' ] = '/method-specific ' ;
652+
653+ \ob_start ();
654+ @$ this ->http ->run (new Request (), new Response (), '1 ' );
655+ $ result = \ob_get_contents ();
656+ \ob_end_clean ();
657+
658+ $ this ->assertEquals ('POST ROUTE ' , $ result , "Method-specific POST route did not match " );
659+
660+ // Restore original server state
661+ $ _SERVER ['REQUEST_METHOD ' ] = $ method ;
662+ $ _SERVER ['REQUEST_URI ' ] = $ uri ;
663+ }
590664}
0 commit comments