File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616use CodeIgniter \Config \Factories ;
1717use CodeIgniter \Events \Events ;
1818use CodeIgniter \Exceptions \PageNotFoundException ;
19+ use CodeIgniter \Exceptions \RuntimeException ;
1920use CodeIgniter \HTTP \Method ;
2021use CodeIgniter \HTTP \Response ;
2122use CodeIgniter \Test \Mock \MockCodeIgniter ;
@@ -689,4 +690,33 @@ public function testForceGlobalSecureRequests(): void
689690 // Do not redirect.
690691 $ response ->assertStatus (200 );
691692 }
693+
694+ #[DataProvider('provideWithRoutesWithInvalidMethod ' )]
695+ public function testWithRoutesWithInvalidMethod (string $ method ): void
696+ {
697+ $ this ->expectException (RuntimeException::class);
698+ $ this ->expectExceptionMessage (sprintf ('Invalid HTTP method "%s" provided for route "home". ' , $ method ));
699+
700+ $ this ->withRoutes ([
701+ [
702+ $ method ,
703+ 'home ' ,
704+ static fn (): string => 'Hello World ' ,
705+ ],
706+ ]);
707+ }
708+
709+ /**
710+ * @return iterable<string, array{0: string}>
711+ */
712+ public static function provideWithRoutesWithInvalidMethod (): iterable
713+ {
714+ foreach (['ADD ' , 'CLI ' , ...Method::all ()] as $ method ) {
715+ yield "wrong {$ method }" => [$ method . 'S ' ];
716+ }
717+
718+ yield 'route collection addRedirect ' => ['addRedirect ' ];
719+
720+ yield 'route collection setHTTPVerb ' => ['setHTTPVerb ' ];
721+ }
692722}
You can’t perform that action at this time.
0 commit comments