Skip to content

Commit ff0c9b3

Browse files
committed
refactor: test for index page and subdir combinations
Refactors testCreateFromStringWithIndexPageSubDirCombinations to use a data provider for better clarity and maintainability. The test now receives parameters for subdirectory and index page, and the data provider supplies various combinations to test route detection.
1 parent ee2013d commit ff0c9b3

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

tests/system/HTTP/SiteURIFactoryTest.php

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -172,45 +172,51 @@ public static function provideCreateFromStringWithoutIndexPage(): iterable
172172
];
173173
}
174174

175-
public function testCreateFromStringWithIndexPageSubDirCombinations(): void
175+
#[DataProvider('provideCreateFromStringWithIndexPageSubDirCombinations')]
176+
public function testCreateFromStringWithIndexPageSubDirCombinations(
177+
string $subDir,
178+
string $indexPage,
179+
): void {
180+
$standardUrl = 'http://localhost:8080';
181+
$standardScriptName = '/public/index.php';
182+
183+
$route = 'controller/method';
184+
config(App::class)->baseURL = $standardUrl . $subDir;
185+
config(App::class)->indexPage = $indexPage;
186+
187+
$_SERVER['PATH_INFO'] = '/' . $route;
188+
$_SERVER['REQUEST_URI'] = $subDir . '/' . $indexPage . $_SERVER['PATH_INFO'];
189+
$_SERVER['SCRIPT_NAME'] = $subDir . $standardScriptName;
190+
$_SERVER['HTTP_HOST'] = $standardUrl;
191+
192+
$factory = $this->createSiteURIFactory();
193+
$detectedRoutePath = $factory->detectRoutePath();
194+
$this->assertSame($route, $detectedRoutePath);
195+
}
196+
197+
public static function provideCreateFromStringWithIndexPageSubDirCombinations(): iterable
176198
{
177-
$standardUrl = 'http://localhost:8080';
178-
$subDirectoryAppsOptions = [
179-
[
180-
'subDir' => '',
181-
'indexPage' => '',
199+
return [
200+
'no subdir and no index' => [
201+
'',
202+
'',
182203
],
183-
[
184-
'subDir' => '',
185-
'indexPage' => 'index.php',
204+
'no subdir and index' => [
205+
'',
206+
'index.php',
186207
],
187-
[
188-
'subDir' => '/subdir',
189-
'indexPage' => '',
208+
'subdir and no index' => [
209+
'/subdir',
210+
'',
190211
],
191-
[
192-
'subDir' => '/subdir',
193-
'indexPage' => 'index.php',
212+
'subdir and index' => [
213+
'/subdir',
214+
'index.php',
194215
],
195-
[
196-
'subDir' => '/subdir/subsubdir',
197-
'indexPage' => 'index.php',
216+
'subdir 2 levels deep string and index' => [
217+
'/subdir/subsubdir',
218+
'index.php',
198219
],
199220
];
200-
201-
foreach ($subDirectoryAppsOptions as $option) {
202-
$route = 'woot';
203-
config(App::class)->baseURL = $standardUrl . $option['subDir'];
204-
config(App::class)->indexPage = $option['indexPage'];
205-
206-
$_SERVER['PATH_INFO'] = '/' . $route;
207-
$_SERVER['REQUEST_URI'] = $option['subDir'] . '/' . $option['indexPage'] . $_SERVER['PATH_INFO'];
208-
$_SERVER['SCRIPT_NAME'] = $option['subDir'] . '/' . $option['indexPage'];
209-
$_SERVER['HTTP_HOST'] = $standardUrl;
210-
211-
$factory = $this->createSiteURIFactory();
212-
$detectedRoutePath = $factory->detectRoutePath();
213-
$this->assertSame($route, $detectedRoutePath);
214-
}
215221
}
216222
}

0 commit comments

Comments
 (0)