From 791bcbd9525cccc6bad721f95edf2a9062db7e29 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Wed, 25 Feb 2026 02:11:55 +0800 Subject: [PATCH] refactor: use uppercase HTTP method names in `FeatureTestTrait` --- system/Test/FeatureTestTrait.php | 30 ++----------------- user_guide_src/source/changelogs/v4.8.0.rst | 3 ++ user_guide_src/source/testing/feature.rst | 4 +-- user_guide_src/source/testing/feature/002.php | 2 +- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php index 618a2bcdb485..a473f8f5cf84 100644 --- a/system/Test/FeatureTestTrait.php +++ b/system/Test/FeatureTestTrait.php @@ -68,19 +68,7 @@ protected function withRoutes(?array $routes = null) $collection->resetRoutes(); foreach ($routes as $route) { - if ($route[0] === strtolower($route[0])) { - @trigger_error( - 'Passing lowercase HTTP method "' . $route[0] . '" is deprecated.' - . ' Use uppercase HTTP method like "' . strtoupper($route[0]) . '".', - E_USER_DEPRECATED, - ); - } - - /** - * @TODO For backward compatibility. Remove strtolower() in the future. - * @deprecated 4.5.0 - */ - $method = strtolower($route[0]); + $method = strtolower($route[0]); // convert to method of RouteCollection if (isset($route[3])) { $collection->{$method}($route[1], $route[2], $route[3]); @@ -173,26 +161,12 @@ public function skipEvents() * Calls a single URI, executes it, and returns a TestResponse * instance that can be used to run many assertions against. * - * @param string $method HTTP verb + * @param uppercase-string $method HTTP verb * * @return TestResponse */ public function call(string $method, string $path, ?array $params = null) { - if ($method === strtolower($method)) { - @trigger_error( - 'Passing lowercase HTTP method "' . $method . '" is deprecated.' - . ' Use uppercase HTTP method like "' . strtoupper($method) . '".', - E_USER_DEPRECATED, - ); - } - - /** - * @deprecated 4.5.0 - * @TODO remove this in the future. - */ - $method = strtoupper($method); - // Simulate having a blank session $_SESSION = []; service('superglobals')->setServer('REQUEST_METHOD', $method); diff --git a/user_guide_src/source/changelogs/v4.8.0.rst b/user_guide_src/source/changelogs/v4.8.0.rst index ee6b70d4fb68..0fdc91c72140 100644 --- a/user_guide_src/source/changelogs/v4.8.0.rst +++ b/user_guide_src/source/changelogs/v4.8.0.rst @@ -26,6 +26,9 @@ Behavior Changes - **Commands:** The ``filter:check`` command now requires the HTTP method argument to be uppercase (e.g., ``spark filter:check GET /`` instead of ``spark filter:check get /``). - **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method (e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match. +- **Testing:** Tests using the ``FeatureTestTrait`` must now use uppercase HTTP method names when performing a request when using the ``call()`` method directly + (e.g., ``$this->call('GET', '/path')`` instead of ``$this->call('get', '/path')``). Additionally, setting method-based routes using ``withRoutes()`` must + also use uppercase method names (e.g., ``$this->withRoutes([['GET', 'home', 'Home::index']])``). Interface Changes ================= diff --git a/user_guide_src/source/testing/feature.rst b/user_guide_src/source/testing/feature.rst index 67337fa0464c..bccefdf3b0df 100644 --- a/user_guide_src/source/testing/feature.rst +++ b/user_guide_src/source/testing/feature.rst @@ -29,7 +29,7 @@ Requesting a Page Essentially, feature tests simply allows you to call an endpoint on your application and get the results back. To do this, you use the ``call()`` method. -1. The first parameter is the HTTP method to use (most frequently either ``GET`` or ``POST``). +1. The first parameter is the uppercase HTTP method to use (most frequently either ``GET`` or ``POST``). 2. The second parameter is the URI path on your site to test. 3. The third parameter ``$params`` accepts an array that is used to populate the superglobal variables for the HTTP verb you are using. So, a method of **GET** @@ -60,7 +60,7 @@ override any existing routes in the system: .. literalinclude:: feature/004.php :lines: 2- -Each of the "routes" is a 3 element array containing the HTTP verb (or "add" for all), +Each of the "routes" is a 3 element array containing the uppercase HTTP verb (or "add" for all), the URI to match, and the routing destination. .. _feature-setting-session-values: diff --git a/user_guide_src/source/testing/feature/002.php b/user_guide_src/source/testing/feature/002.php index a47406b24aeb..37022ddff517 100644 --- a/user_guide_src/source/testing/feature/002.php +++ b/user_guide_src/source/testing/feature/002.php @@ -4,7 +4,7 @@ $result = $this->call('GET', '/'); // Submit a form -$result = $this->call('post', 'contact', [ +$result = $this->call('POST', 'contact', [ 'name' => 'Fred Flintstone', 'email' => 'flintyfred@example.com', ]);