1818use Tests \Support \Controllers \Hello ;
1919
2020/**
21- * @backupGlobals enabled
22- *
2321 * @internal
2422 */
2523final class RouteCollectionTest extends CIUnitTestCase
2624{
25+ protected function setUp (): void
26+ {
27+ parent ::setUp ();
28+
29+ $ this ->resetServices ();
30+ }
31+
2732 protected function getCollector (array $ config = [], array $ files = [], $ moduleConfig = null )
2833 {
2934 $ defaults = [
@@ -1062,49 +1067,46 @@ public function testAddRedirectGetMethod()
10621067 */
10631068 public function testWithSubdomain ()
10641069 {
1065- $ routes = $ this ->getCollector ();
1066-
10671070 $ _SERVER ['HTTP_HOST ' ] = 'adm.example.com ' ;
10681071
1072+ $ routes = $ this ->getCollector ();
1073+
10691074 $ routes ->add ('/objects/(:alphanum) ' , 'Admin::objectsList/$1 ' , ['subdomain ' => 'adm ' ]);
10701075 $ routes ->add ('/objects/(:alphanum) ' , 'App::objectsList/$1 ' );
10711076
10721077 $ expects = [
10731078 'objects/([a-zA-Z0-9]+) ' => '\Admin::objectsList/$1 ' ,
10741079 ];
1075-
10761080 $ this ->assertSame ($ expects , $ routes ->getRoutes ());
10771081 }
10781082
10791083 public function testWithSubdomainMissing ()
10801084 {
1081- $ routes = $ this -> getCollector () ;
1085+ $ _SERVER [ ' HTTP_HOST ' ] = ' www.example.com ' ;
10821086
1083- // $_SERVER['HTTP_HOST'] = 'adm.example.com' ;
1087+ $ routes = $ this -> getCollector () ;
10841088
10851089 $ routes ->add ('/objects/(:alphanum) ' , 'Admin::objectsList/$1 ' , ['subdomain ' => 'adm ' ]);
10861090 $ routes ->add ('/objects/(:alphanum) ' , 'App::objectsList/$1 ' );
10871091
10881092 $ expects = [
10891093 'objects/([a-zA-Z0-9]+) ' => '\App::objectsList/$1 ' ,
10901094 ];
1091-
10921095 $ this ->assertSame ($ expects , $ routes ->getRoutes ());
10931096 }
10941097
10951098 public function testWithDifferentSubdomain ()
10961099 {
1097- $ routes = $ this ->getCollector ();
1098-
10991100 $ _SERVER ['HTTP_HOST ' ] = 'adm.example.com ' ;
11001101
1102+ $ routes = $ this ->getCollector ();
1103+
11011104 $ routes ->add ('/objects/(:alphanum) ' , 'Admin::objectsList/$1 ' , ['subdomain ' => 'sales ' ]);
11021105 $ routes ->add ('/objects/(:alphanum) ' , 'App::objectsList/$1 ' );
11031106
11041107 $ expects = [
11051108 'objects/([a-zA-Z0-9]+) ' => '\App::objectsList/$1 ' ,
11061109 ];
1107-
11081110 $ this ->assertSame ($ expects , $ routes ->getRoutes ());
11091111 }
11101112
@@ -1381,10 +1383,10 @@ public function testOffsetParameters()
13811383 */
13821384 public function testRouteToWithSubdomainMatch ()
13831385 {
1384- $ routes = $ this ->getCollector ();
1385-
1386- Services::request ()->setMethod ('get ' );
13871386 $ _SERVER ['HTTP_HOST ' ] = 'doc.example.com ' ;
1387+ Services::request ()->setMethod ('get ' );
1388+
1389+ $ routes = $ this ->getCollector ();
13881390
13891391 $ routes ->get ('i/(:any) ' , 'App\Controllers\Site\CDoc::item/$1 ' , ['subdomain ' => 'doc ' , 'as ' => 'doc_item ' ]);
13901392
@@ -1393,10 +1395,10 @@ public function testRouteToWithSubdomainMatch()
13931395
13941396 public function testRouteToWithSubdomainMismatch ()
13951397 {
1396- $ routes = $ this ->getCollector ();
1397-
1398- Services::request ()->setMethod ('get ' );
13991398 $ _SERVER ['HTTP_HOST ' ] = 'dev.example.com ' ;
1399+ Services::request ()->setMethod ('get ' );
1400+
1401+ $ routes = $ this ->getCollector ();
14001402
14011403 $ routes ->get ('i/(:any) ' , 'App\Controllers\Site\CDoc::item/$1 ' , ['subdomain ' => 'doc ' , 'as ' => 'doc_item ' ]);
14021404
@@ -1453,10 +1455,10 @@ public function testRouteToWithGenericSubdomainNot()
14531455
14541456 public function testRouteToWithoutSubdomainMatch ()
14551457 {
1456- $ routes = $ this ->getCollector ();
1457-
1458- Services::request ()->setMethod ('get ' );
14591458 $ _SERVER ['HTTP_HOST ' ] = 'doc.example.com ' ;
1459+ Services::request ()->setMethod ('get ' );
1460+
1461+ $ routes = $ this ->getCollector ();
14601462
14611463 $ routes ->get ('i/(:any) ' , 'App\Controllers\Site\CDoc::item/$1 ' , ['hostname ' => 'example.com ' , 'as ' => 'doc_item ' ]);
14621464
@@ -1477,10 +1479,10 @@ public function testRouteToWithoutSubdomainMismatch()
14771479
14781480 public function testRouteToWithoutSubdomainNot ()
14791481 {
1480- $ routes = $ this ->getCollector ();
1481-
1482- Services::request ()->setMethod ('get ' );
14831482 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
1483+ Services::request ()->setMethod ('get ' );
1484+
1485+ $ routes = $ this ->getCollector ();
14841486
14851487 $ routes ->get ('i/(:any) ' , 'App\Controllers\Site\CDoc::item/$1 ' , ['hostname ' => 'example.com ' , 'as ' => 'doc_item ' ]);
14861488
@@ -1494,8 +1496,8 @@ public function testRouteToWithoutSubdomainNot()
14941496 */
14951497 public function testRouteOverwritingDifferentSubdomains ()
14961498 {
1497- Services::request ()->setMethod ('get ' );
14981499 $ _SERVER ['HTTP_HOST ' ] = 'doc.domain.com ' ;
1500+ Services::request ()->setMethod ('get ' );
14991501
15001502 $ routes = $ this ->getCollector ();
15011503 $ router = new Router ($ routes , Services::request ());
0 commit comments