@@ -955,6 +955,12 @@ public function testStartControllerPermitsInvoke(): void
955955 {
956956 $ this ->setPrivateProperty ($ this ->codeigniter , 'benchmark ' , new Timer ());
957957 $ this ->setPrivateProperty ($ this ->codeigniter , 'controller ' , '\\' . Home::class);
958+
959+ // Set up the router with routes
960+ $ routes = service ('routes ' );
961+ $ router = service ('router ' , $ routes , service ('incomingrequest ' ));
962+ $ this ->setPrivateProperty ($ this ->codeigniter , 'router ' , $ router );
963+
958964 $ startController = self ::getPrivateMethodInvoker ($ this ->codeigniter , 'startController ' );
959965
960966 $ this ->setPrivateProperty ($ this ->codeigniter , 'method ' , '__invoke ' );
@@ -969,9 +975,9 @@ public function testRouteAttributeCacheIntegration(): void
969975 $ _SERVER ['argv ' ] = ['index.php ' , 'attribute/cached ' ];
970976 $ _SERVER ['argc ' ] = 2 ;
971977
972- $ _SERVER [ 'REQUEST_URI ' ] = '/attribute/cached ' ;
973- $ _SERVER [ 'SCRIPT_NAME ' ] = '/index.php ' ;
974- $ _SERVER [ 'REQUEST_METHOD ' ] = 'GET ' ;
978+ Services:: superglobals ()-> setServer ( 'REQUEST_URI ' , '/attribute/cached ' ) ;
979+ Services:: superglobals ()-> setServer ( 'SCRIPT_NAME ' , '/index.php ' ) ;
980+ Services:: superglobals ()-> setServer ( 'REQUEST_METHOD ' , 'GET ' ) ;
975981
976982 // Clear cache before test
977983 cache ()->clean ();
@@ -1000,9 +1006,9 @@ public function testRouteAttributeCacheIntegration(): void
10001006 $ this ->resetServices ();
10011007 $ _SERVER ['argv ' ] = ['index.php ' , 'attribute/cached ' ];
10021008 $ _SERVER ['argc ' ] = 2 ;
1003- $ _SERVER [ 'REQUEST_URI ' ] = '/attribute/cached ' ;
1004- $ _SERVER [ 'SCRIPT_NAME ' ] = '/index.php ' ;
1005- $ _SERVER [ 'REQUEST_METHOD ' ] = 'GET ' ;
1009+ Services:: superglobals ()-> setServer ( 'REQUEST_URI ' , '/attribute/cached ' ) ;
1010+ Services:: superglobals ()-> setServer ( 'SCRIPT_NAME ' , '/index.php ' ) ;
1011+ Services:: superglobals ()-> setServer ( 'REQUEST_METHOD ' , 'GET ' ) ;
10061012 $ this ->codeigniter = new MockCodeIgniter (new App ());
10071013
10081014 $ routes = service ('routes ' );
@@ -1029,8 +1035,8 @@ public function testRouteAttributeFilterIntegration(): void
10291035 $ _SERVER ['argv ' ] = ['index.php ' , 'attribute/filtered ' ];
10301036 $ _SERVER ['argc ' ] = 2 ;
10311037
1032- $ _SERVER [ 'REQUEST_URI ' ] = '/attribute/filtered ' ;
1033- $ _SERVER [ 'SCRIPT_NAME ' ] = '/index.php ' ;
1038+ Services:: superglobals ()-> setServer ( 'REQUEST_URI ' , '/attribute/filtered ' ) ;
1039+ Services:: superglobals ()-> setServer ( 'SCRIPT_NAME ' , '/index.php ' ) ;
10341040
10351041 // Register the test filter
10361042 $ filterConfig = config ('Filters ' );
@@ -1057,8 +1063,8 @@ public function testRouteAttributeRestrictIntegration(): void
10571063 $ _SERVER ['argv ' ] = ['index.php ' , 'attribute/restricted ' ];
10581064 $ _SERVER ['argc ' ] = 2 ;
10591065
1060- $ _SERVER [ 'REQUEST_URI ' ] = '/attribute/restricted ' ;
1061- $ _SERVER [ 'SCRIPT_NAME ' ] = '/index.php ' ;
1066+ Services:: superglobals ()-> setServer ( 'REQUEST_URI ' , '/attribute/restricted ' ) ;
1067+ Services:: superglobals ()-> setServer ( 'SCRIPT_NAME ' , '/index.php ' ) ;
10621068
10631069 // Inject mock router
10641070 $ routes = service ('routes ' );
@@ -1079,8 +1085,8 @@ public function testRouteAttributeRestrictThrowsException(): void
10791085 $ _SERVER ['argv ' ] = ['index.php ' , 'attribute/restricted ' ];
10801086 $ _SERVER ['argc ' ] = 2 ;
10811087
1082- $ _SERVER [ 'REQUEST_URI ' ] = '/attribute/shouldBeRestricted ' ;
1083- $ _SERVER [ 'SCRIPT_NAME ' ] = '/index.php ' ;
1088+ Services:: superglobals ()-> setServer ( 'REQUEST_URI ' , '/attribute/shouldBeRestricted ' ) ;
1089+ Services:: superglobals ()-> setServer ( 'SCRIPT_NAME ' , '/index.php ' ) ;
10841090
10851091 // Inject mock router
10861092 $ routes = service ('routes ' );
@@ -1100,8 +1106,8 @@ public function testRouteAttributeMultipleAttributesIntegration(): void
11001106 $ _SERVER ['argv ' ] = ['index.php ' , 'attribute/multiple ' ];
11011107 $ _SERVER ['argc ' ] = 2 ;
11021108
1103- $ _SERVER [ 'REQUEST_URI ' ] = '/attribute/multiple ' ;
1104- $ _SERVER [ 'SCRIPT_NAME ' ] = '/index.php ' ;
1109+ Services:: superglobals ()-> setServer ( 'REQUEST_URI ' , '/attribute/multiple ' ) ;
1110+ Services:: superglobals ()-> setServer ( 'SCRIPT_NAME ' , '/index.php ' ) ;
11051111
11061112 // Register the test filter
11071113 $ filterConfig = config ('Filters ' );
@@ -1128,8 +1134,8 @@ public function testRouteAttributeNoAttributesIntegration(): void
11281134 $ _SERVER ['argv ' ] = ['index.php ' , 'attribute/none ' ];
11291135 $ _SERVER ['argc ' ] = 2 ;
11301136
1131- $ _SERVER [ 'REQUEST_URI ' ] = '/attribute/none ' ;
1132- $ _SERVER [ 'SCRIPT_NAME ' ] = '/index.php ' ;
1137+ Services:: superglobals ()-> setServer ( 'REQUEST_URI ' , '/attribute/none ' ) ;
1138+ Services:: superglobals ()-> setServer ( 'SCRIPT_NAME ' , '/index.php ' ) ;
11331139
11341140 // Inject mock router
11351141 $ routes = service ('routes ' );
@@ -1150,9 +1156,9 @@ public function testRouteAttributeCustomCacheKeyIntegration(): void
11501156 $ _SERVER ['argv ' ] = ['index.php ' , 'attribute/customkey ' ];
11511157 $ _SERVER ['argc ' ] = 2 ;
11521158
1153- $ _SERVER [ 'REQUEST_URI ' ] = '/attribute/customkey ' ;
1154- $ _SERVER [ 'SCRIPT_NAME ' ] = '/index.php ' ;
1155- $ _SERVER [ 'REQUEST_METHOD ' ] = 'GET ' ;
1159+ Services:: superglobals ()-> setServer ( 'REQUEST_URI ' , '/attribute/customkey ' ) ;
1160+ Services:: superglobals ()-> setServer ( 'SCRIPT_NAME ' , '/index.php ' ) ;
1161+ Services:: superglobals ()-> setServer ( 'REQUEST_METHOD ' , 'GET ' ) ;
11561162
11571163 // Clear cache before test
11581164 cache ()->clean ();
@@ -1166,14 +1172,14 @@ public function testRouteAttributeCustomCacheKeyIntegration(): void
11661172 // First request
11671173 ob_start ();
11681174 $ this ->codeigniter ->run ();
1169- $ output1 = ob_get_clean ();
1175+ ob_get_clean ();
11701176
11711177 // Verify custom cache key was used
11721178 $ cached = cache ('custom_cache_key ' );
11731179 $ this ->assertNotNull ($ cached );
11741180 $ this ->assertIsArray ($ cached );
11751181 $ this ->assertArrayHasKey ('body ' , $ cached );
1176- $ this ->assertStringContainsString ('Custom key content at ' , $ cached ['body ' ]);
1182+ $ this ->assertStringContainsString ('Custom key content at ' , ( string ) $ cached ['body ' ]);
11771183
11781184 // Clear cache after test
11791185 cache ()->clean ();
0 commit comments