Skip to content

Commit c247f6e

Browse files
committed
test: make request-order fixtures deterministic and document REQUEST mutations
Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
1 parent 5d28859 commit c247f6e

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎system/HTTP/SiteURIFactory.php‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/**
2121
* Creates SiteURI using superglobals.
2222
*
23+
* This class also updates superglobal $_REQUEST.
2324
* This class also updates superglobal $_SERVER and $_GET.
2425
*
2526
* @see \CodeIgniter\HTTP\SiteURIFactoryTest
@@ -33,7 +34,7 @@ public function __construct(private App $appConfig, private Superglobals $superg
3334
/**
3435
* Create the current URI object from superglobals.
3536
*
36-
* This method updates superglobal $_SERVER and $_GET.
37+
* This method updates superglobals $_SERVER, $_GET, and $_REQUEST.
3738
*/
3839
public function createFromGlobals(): SiteURI
3940
{
@@ -105,7 +106,7 @@ public function detectRoutePath(string $protocol = ''): string
105106
* Will parse the REQUEST_URI and automatically detect the URI from it,
106107
* fixing the query string if necessary.
107108
*
108-
* This method updates superglobal $_SERVER and $_GET.
109+
* This method updates superglobals $_SERVER, $_GET, and $_REQUEST.
109110
*
110111
* @return string The route path (before normalization).
111112
*/
@@ -181,7 +182,7 @@ private function parseRequestURI(): string
181182
/**
182183
* Will parse QUERY_STRING and automatically detect the URI from it.
183184
*
184-
* This method updates superglobal $_SERVER and $_GET.
185+
* This method updates superglobals $_SERVER, $_GET, and $_REQUEST.
185186
*
186187
* @return string The route path (before normalization).
187188
*/

‎tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ public function testQueryStringWithQueryString(): void
260260

261261
public function testQueryStringRefreshesRequestWithoutOverwritingCustomValues(): void
262262
{
263+
if (! $this->effectiveRequestOrderIncludesGet()) {
264+
$this->markTestSkipped('The effective request order does not include GET.');
265+
}
266+
263267
$superglobals = new Superglobals(
264268
[
265269
'REQUEST_URI' => '/index.php?/ci/woot?code=good',
@@ -297,6 +301,10 @@ public function testQueryStringRefreshesRequestWithoutOverwritingCustomValues():
297301

298302
public function testRequestURIRefreshesRequestForValidation(): void
299303
{
304+
if (! $this->effectiveRequestOrderIncludesGet()) {
305+
$this->markTestSkipped('The effective request order does not include GET.');
306+
}
307+
300308
$superglobals = new Superglobals(
301309
[
302310
'REQUEST_URI' => '/index.php/woot?code=good',
@@ -322,6 +330,27 @@ public function testRequestURIRefreshesRequestForValidation(): void
322330
$this->assertTrue(service('validation')->withRequest($request)->setRules(['code' => 'in_list[good]'])->run());
323331
}
324332

333+
/**
334+
* Whether GET is part of the effective request order on this host.
335+
*
336+
* Mirrors Superglobals::getRequestData(): uses `request_order`, falls
337+
* back to `variables_order`, then to PHP's default GP.
338+
*/
339+
private function effectiveRequestOrderIncludesGet(): bool
340+
{
341+
$order = (string) ini_get('request_order');
342+
343+
if ($order === '') {
344+
$order = (string) ini_get('variables_order');
345+
}
346+
347+
if ($order === '') {
348+
$order = 'GP';
349+
}
350+
351+
return str_contains(strtoupper($order), 'G');
352+
}
353+
325354
public function testQueryStringEmpty(): void
326355
{
327356
// /index.php?

‎tests/system/SuperglobalsTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function testGetRequestDataMergesGetAndPost(): void
307307
$this->superglobals->setGetArray(['get_key' => 'get_value']);
308308
$this->superglobals->setPostArray(['post_key' => 'post_value']);
309309

310-
$data = $this->superglobals->getRequestData();
310+
$data = $this->superglobals->getRequestData('GP');
311311

312312
$this->assertSame('get_value', $data['get_key']);
313313
$this->assertSame('post_value', $data['post_key']);
@@ -317,12 +317,12 @@ public function testGetRequestDataReflectsGetChanges(): void
317317
{
318318
$this->superglobals->setGetArray(['key' => 'old']);
319319

320-
$this->assertSame('old', $this->superglobals->getRequestData()['key']);
320+
$this->assertSame('old', $this->superglobals->getRequestData('G')['key']);
321321

322322
// Simulate SiteURIFactory updating $_GET after the request started.
323323
$this->superglobals->setGetArray(['key' => 'new']);
324324

325-
$this->assertSame('new', $this->superglobals->getRequestData()['key']);
325+
$this->assertSame('new', $this->superglobals->getRequestData('G')['key']);
326326
}
327327

328328
public function testGetRequestDataMergesCookie(): void

0 commit comments

Comments
 (0)