From 6107a6059102ba4c49a1f5b39a758f519bdcbbb6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 19 Jun 2024 12:29:48 +0900 Subject: [PATCH 1/3] test: add `spark routes` test for route with regexp --- tests/system/Commands/RoutesTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/system/Commands/RoutesTest.php b/tests/system/Commands/RoutesTest.php index 4c0ffd174550..2ee9f44f1bac 100644 --- a/tests/system/Commands/RoutesTest.php +++ b/tests/system/Commands/RoutesTest.php @@ -240,4 +240,18 @@ public function testRoutesCommandRouteLegacy(): void EOL; $this->assertStringContainsString($expected, $this->getBuffer()); } + + public function testRoutesCommandRouteWithRegexp(): void + { + $routes = Services::routes(); + $routes->resetRoutes(); + $routes->options('picker/(.+)', 'Options::index'); + + command('routes'); + + $expected = <<<'EOL' + | OPTIONS | picker/(.+) | ยป | \App\Controllers\Options::index | | | + EOL; + $this->assertStringContainsString($expected, $this->getBuffer()); + } } From adbc2910e43f62d342c95a8448217427fc22d9c5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 19 Jun 2024 12:31:29 +0900 Subject: [PATCH 2/3] fix: `spark routes` may show BadRequestException when regexp is in route E.g., CodeIgniter\HTTP\Exceptions\BadRequestException: The URI you submitted has disallowed characters: "(. )" --- system/Commands/Utilities/Routes/FilterFinder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Commands/Utilities/Routes/FilterFinder.php b/system/Commands/Utilities/Routes/FilterFinder.php index 82ea26979517..7971e5c1be84 100644 --- a/system/Commands/Utilities/Routes/FilterFinder.php +++ b/system/Commands/Utilities/Routes/FilterFinder.php @@ -15,6 +15,7 @@ use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Filters\Filters; +use CodeIgniter\HTTP\Exceptions\BadRequestException; use CodeIgniter\HTTP\Exceptions\RedirectException; use CodeIgniter\Router\Router; use Config\Feature; @@ -72,7 +73,7 @@ public function find(string $uri): array 'before' => [], 'after' => [], ]; - } catch (PageNotFoundException) { + } catch (BadRequestException|PageNotFoundException) { return [ 'before' => [''], 'after' => [''], From 4ad4bd35e61ecaf348f8957af115cb9a7c81922f Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 19 Jun 2024 12:38:20 +0900 Subject: [PATCH 3/3] docs: add PHPDoc tags --- system/Config/BaseService.php | 6 ++++++ system/Router/Router.php | 1 + 2 files changed, 7 insertions(+) diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index cd770dc667ed..5bd55403beba 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -346,6 +346,8 @@ public static function serviceExists(string $name): ?string * Reset shared instances and mocks for testing. * * @return void + * + * @testTag only available to test code */ public static function reset(bool $initAutoloader = true) { @@ -362,6 +364,8 @@ public static function reset(bool $initAutoloader = true) * Resets any mock and shared instances for a single service. * * @return void + * + * @testTag only available to test code */ public static function resetSingle(string $name) { @@ -375,6 +379,8 @@ public static function resetSingle(string $name) * @param object $mock * * @return void + * + * @testTag only available to test code */ public static function injectMock(string $name, $mock) { diff --git a/system/Router/Router.php b/system/Router/Router.php index de996f534618..dc778cd03ffe 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -187,6 +187,7 @@ public function __construct(RouteCollectionInterface $routes, ?Request $request * * @return (Closure(mixed...): (ResponseInterface|string|void))|string Controller classname or Closure * + * @throws BadRequestException * @throws PageNotFoundException * @throws RedirectException */