From f7223f3b44b8dff7052a66a27b36a1e7251b1c8b Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Mon, 24 Aug 2026 20:45:22 +0800 Subject: [PATCH] refactor: fix iterable types in `Router` tests --- .../system/Router/AutoRouterImprovedTest.php | 6 ++ .../Router/DefinedRouteCollectorTest.php | 3 + .../RouteCollectionReverseRouteTest.php | 7 ++ tests/system/Router/RouteCollectionTest.php | 20 +++++ tests/system/Router/RouterTest.php | 3 + utils/phpstan-baseline/loader.neon | 2 +- .../missingType.iterableValue.neon | 77 +------------------ 7 files changed, 41 insertions(+), 77 deletions(-) diff --git a/tests/system/Router/AutoRouterImprovedTest.php b/tests/system/Router/AutoRouterImprovedTest.php index 8a4132a8f297..a974509e94c4 100644 --- a/tests/system/Router/AutoRouterImprovedTest.php +++ b/tests/system/Router/AutoRouterImprovedTest.php @@ -528,6 +528,9 @@ public function testTranslateUriToCamelCase( ], $router->getPos()); } + /** + * @return iterable + */ public static function provideTranslateUriToCamelCase(): iterable { yield from [ @@ -587,6 +590,9 @@ public function testRejectTranslateUriToCamelCase(string $uri, string $expMsg): $router->getRoute($uri, Method::GET); } + /** + * @return iterable + */ public static function provideRejectTranslateUriToCamelCase(): iterable { yield from [ diff --git a/tests/system/Router/DefinedRouteCollectorTest.php b/tests/system/Router/DefinedRouteCollectorTest.php index 329c582991bf..31a535e130c6 100644 --- a/tests/system/Router/DefinedRouteCollectorTest.php +++ b/tests/system/Router/DefinedRouteCollectorTest.php @@ -25,6 +25,9 @@ #[Group('Others')] final class DefinedRouteCollectorTest extends CIUnitTestCase { + /** + * @param array|non-empty-string> $config + */ private function createRouteCollection(array $config = [], ?Modules $moduleConfig = null): RouteCollection { $defaults = [ diff --git a/tests/system/Router/RouteCollectionReverseRouteTest.php b/tests/system/Router/RouteCollectionReverseRouteTest.php index 66428a13de99..36ead775da06 100644 --- a/tests/system/Router/RouteCollectionReverseRouteTest.php +++ b/tests/system/Router/RouteCollectionReverseRouteTest.php @@ -35,6 +35,10 @@ protected function setUp(): void $this->resetFactories(); } + /** + * @param array|non-empty-string> $config + * @param array $files + */ protected function getCollector(array $config = [], array $files = [], ?Modules $moduleConfig = null): RouteCollection { $defaults = [ @@ -147,6 +151,9 @@ public function testReverseRoutingDefaultNamespaceAppController(string $controll $this->assertSame('/users/15/gallery12', $match); } + /** + * @return iterable + */ public static function provideReverseRoutingDefaultNamespaceAppController(): iterable { return yield from [ diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index e61f8ec472a9..5e3e7bd8015f 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -44,6 +44,10 @@ protected function setUp(): void Services::injectMock('superglobals', new Superglobals()); } + /** + * @param array|non-empty-string> $config + * @param array $files + */ protected function getCollector(array $config = [], array $files = [], ?Modules $moduleConfig = null): RouteCollection { $defaults = [ @@ -507,6 +511,9 @@ static function ($routes): void { $this->assertSame($expected, $routes->getRoutes()); } + /** + * @param array $expected + */ #[DataProvider('provideNestedGroupingWorksWithRootPrefix')] public function testNestedGroupingWorksWithRootPrefix( string $group, @@ -531,6 +538,9 @@ static function ($routes): void { $this->assertSame($expected, $routes->getRoutes()); } + /** + * @return iterable}> + */ public static function provideNestedGroupingWorksWithRootPrefix(): iterable { yield from [ @@ -1343,6 +1353,10 @@ static function (): void {}, $this->assertSame($options, ['as' => 'admin', 'foo' => 'baz']); } + /** + * @param array $options1 + * @param array $options2 + */ #[DataProvider('provideRoutesOptionsWithSameFromTwoRoutes')] public function testRoutesOptionsWithSameFromTwoRoutes(array $options1, array $options2): void { @@ -1366,6 +1380,9 @@ static function (): void {}, $this->assertSame($options, $options1); } + /** + * @return iterable, array}> + */ public static function provideRoutesOptionsWithSameFromTwoRoutes(): iterable { yield from [ @@ -1860,6 +1877,9 @@ public function testRoutesControllerNameReturnsFQCN(string $namespace): void $this->assertSame('\\' . Product::class, $router->controllerName()); } + /** + * @return iterable + */ public static function provideRouteDefaultNamespace(): iterable { return [ diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index 7eef0a7569aa..ec06de96e0b3 100644 --- a/tests/system/Router/RouterTest.php +++ b/tests/system/Router/RouterTest.php @@ -963,6 +963,9 @@ public function testRedirectRoute( $router->handle($url); } + /** + * @return iterable + */ public static function provideRedirectRoute(): iterable { // [$route, $redirectFrom, $redirectTo, $url, $expectedPath, $alias] diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 61ebc04982b4..1e905d3e3a1f 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 419 errors +# total 404 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index 333eaa92ae2e..74128441efa6 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 282 errors +# total 267 errors parameters: ignoreErrors: @@ -1297,81 +1297,6 @@ parameters: count: 1 path: ../../tests/system/RESTful/ResourceControllerTest.php - - - message: '#^Method CodeIgniter\\Router\\AutoRouterImprovedTest\:\:provideRejectTranslateUriToCamelCase\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Router/AutoRouterImprovedTest.php - - - - message: '#^Method CodeIgniter\\Router\\AutoRouterImprovedTest\:\:provideTranslateUriToCamelCase\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Router/AutoRouterImprovedTest.php - - - - message: '#^Method CodeIgniter\\Router\\DefinedRouteCollectorTest\:\:createRouteCollection\(\) has parameter \$config with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Router/DefinedRouteCollectorTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionReverseRouteTest\:\:getCollector\(\) has parameter \$config with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionReverseRouteTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionReverseRouteTest\:\:getCollector\(\) has parameter \$files with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionReverseRouteTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionReverseRouteTest\:\:provideReverseRoutingDefaultNamespaceAppController\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionReverseRouteTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionTest\:\:getCollector\(\) has parameter \$config with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionTest\:\:getCollector\(\) has parameter \$files with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionTest\:\:provideNestedGroupingWorksWithRootPrefix\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionTest\:\:provideRouteDefaultNamespace\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionTest\:\:provideRoutesOptionsWithSameFromTwoRoutes\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionTest\:\:testNestedGroupingWorksWithRootPrefix\(\) has parameter \$expected with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionTest\:\:testRoutesOptionsWithSameFromTwoRoutes\(\) has parameter \$options1 with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionTest\:\:testRoutesOptionsWithSameFromTwoRoutes\(\) has parameter \$options2 with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Router/RouteCollectionTest.php - - - - message: '#^Method CodeIgniter\\Router\\RouterTest\:\:provideRedirectRoute\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Router/RouterTest.php - - message: '#^Method CodeIgniter\\Throttle\\ThrottleTest\:\:provideTokenTimeCalculationUCs\(\) return type has no value type specified in iterable type iterable\.$#' count: 1