From 74d3b2819e0a0589b165138c3ee195a7f2ae360a Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sat, 30 Nov 2024 01:23:07 +0800 Subject: [PATCH] refactor: use `Superglobals` in setting 'REQUEST_METHOD' in `FeatureTestTrait` --- phpstan-baseline.php | 24 +++--------------------- system/Test/FeatureTestTrait.php | 4 ++-- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 67662f829954..e6f139f55012 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -15295,12 +15295,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/HomeTest.php', ]; -$ignoreErrors[] = [ - // identifier: codeigniter.superglobalAccessAssign - 'message' => '#^Assigning string directly on offset \'REQUEST_METHOD\' of \\$_SERVER is discouraged\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/HomeTest.php', -]; $ignoreErrors[] = [ // identifier: empty.notAllowed 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', @@ -15633,13 +15627,13 @@ ]; $ignoreErrors[] = [ // identifier: argument.type - 'message' => '#^Parameter \\#1 \\$row of method CodeIgniter\\\\BaseModel\\:\\:save\\(\\) expects array\\|object, array> given\\.$#', + 'message' => '#^Parameter \\#1 \\$row of method CodeIgniter\\\\BaseModel\\:\\:save\\(\\) expects array\\\\|object, array\\\\> given\\.$#', 'count' => 1, 'path' => __DIR__ . '/tests/system/Models/DataConverterModelTest.php', ]; $ignoreErrors[] = [ // identifier: argument.type - 'message' => '#^Parameter \\#2 \\$row of method CodeIgniter\\\\Model\\:\\:update\\(\\) expects array\\|object\\|null, array> given\\.$#', + 'message' => '#^Parameter \\#2 \\$row of method CodeIgniter\\\\Model\\:\\:update\\(\\) expects array\\\\|object\\|null, array\\\\> given\\.$#', 'count' => 1, 'path' => __DIR__ . '/tests/system/Models/DataConverterModelTest.php', ]; @@ -16029,7 +16023,7 @@ ]; $ignoreErrors[] = [ // identifier: argument.type - 'message' => '#^Parameter \\#1 \\$row of method CodeIgniter\\\\BaseModel\\:\\:save\\(\\) expects array\\|object, array\\|null given\\.$#', + 'message' => '#^Parameter \\#1 \\$row of method CodeIgniter\\\\BaseModel\\:\\:save\\(\\) expects array\\\\|object, array\\\\|null given\\.$#', 'count' => 1, 'path' => __DIR__ . '/tests/system/Models/UpdateModelTest.php', ]; @@ -17089,12 +17083,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/Test/FeatureTestAutoRoutingImprovedTest.php', ]; -$ignoreErrors[] = [ - // identifier: codeigniter.superglobalAccessAssign - 'message' => '#^Assigning string directly on offset \'REQUEST_METHOD\' of \\$_SERVER is discouraged\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/Test/FeatureTestAutoRoutingImprovedTest.php', -]; $ignoreErrors[] = [ // identifier: empty.notAllowed 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', @@ -17203,12 +17191,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/Test/FeatureTestTraitTest.php', ]; -$ignoreErrors[] = [ - // identifier: codeigniter.superglobalAccessAssign - 'message' => '#^Assigning string directly on offset \'REQUEST_METHOD\' of \\$_SERVER is discouraged\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/Test/FeatureTestTraitTest.php', -]; $ignoreErrors[] = [ // identifier: empty.notAllowed 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php index a1d492f85fdd..083313dfa7e2 100644 --- a/system/Test/FeatureTestTrait.php +++ b/system/Test/FeatureTestTrait.php @@ -179,8 +179,8 @@ public function call(string $method, string $path, ?array $params = null) $method = strtoupper($method); // Simulate having a blank session - $_SESSION = []; - $_SERVER['REQUEST_METHOD'] = $method; + $_SESSION = []; + service('superglobals')->setServer('REQUEST_METHOD', $method); $request = $this->setupRequest($method, $path); $request = $this->setupHeaders($request);