Skip to content

Commit 791bcbd

Browse files
committed
refactor: use uppercase HTTP method names in FeatureTestTrait
1 parent 1172c8c commit 791bcbd

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed

system/Test/FeatureTestTrait.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,7 @@ protected function withRoutes(?array $routes = null)
6868
$collection->resetRoutes();
6969

7070
foreach ($routes as $route) {
71-
if ($route[0] === strtolower($route[0])) {
72-
@trigger_error(
73-
'Passing lowercase HTTP method "' . $route[0] . '" is deprecated.'
74-
. ' Use uppercase HTTP method like "' . strtoupper($route[0]) . '".',
75-
E_USER_DEPRECATED,
76-
);
77-
}
78-
79-
/**
80-
* @TODO For backward compatibility. Remove strtolower() in the future.
81-
* @deprecated 4.5.0
82-
*/
83-
$method = strtolower($route[0]);
71+
$method = strtolower($route[0]); // convert to method of RouteCollection
8472

8573
if (isset($route[3])) {
8674
$collection->{$method}($route[1], $route[2], $route[3]);
@@ -173,26 +161,12 @@ public function skipEvents()
173161
* Calls a single URI, executes it, and returns a TestResponse
174162
* instance that can be used to run many assertions against.
175163
*
176-
* @param string $method HTTP verb
164+
* @param uppercase-string $method HTTP verb
177165
*
178166
* @return TestResponse
179167
*/
180168
public function call(string $method, string $path, ?array $params = null)
181169
{
182-
if ($method === strtolower($method)) {
183-
@trigger_error(
184-
'Passing lowercase HTTP method "' . $method . '" is deprecated.'
185-
. ' Use uppercase HTTP method like "' . strtoupper($method) . '".',
186-
E_USER_DEPRECATED,
187-
);
188-
}
189-
190-
/**
191-
* @deprecated 4.5.0
192-
* @TODO remove this in the future.
193-
*/
194-
$method = strtoupper($method);
195-
196170
// Simulate having a blank session
197171
$_SESSION = [];
198172
service('superglobals')->setServer('REQUEST_METHOD', $method);

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Behavior Changes
2626
- **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 /``).
2727
- **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method
2828
(e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match.
29+
- **Testing:** Tests using the ``FeatureTestTrait`` must now use uppercase HTTP method names when performing a request when using the ``call()`` method directly
30+
(e.g., ``$this->call('GET', '/path')`` instead of ``$this->call('get', '/path')``). Additionally, setting method-based routes using ``withRoutes()`` must
31+
also use uppercase method names (e.g., ``$this->withRoutes([['GET', 'home', 'Home::index']])``).
2932

3033
Interface Changes
3134
=================

user_guide_src/source/testing/feature.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Requesting a Page
2929
Essentially, feature tests simply allows you to call an endpoint on your application and get the results back.
3030
To do this, you use the ``call()`` method.
3131

32-
1. The first parameter is the HTTP method to use (most frequently either ``GET`` or ``POST``).
32+
1. The first parameter is the uppercase HTTP method to use (most frequently either ``GET`` or ``POST``).
3333
2. The second parameter is the URI path on your site to test.
3434
3. The third parameter ``$params`` accepts an array that is used to populate the
3535
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:
6060
.. literalinclude:: feature/004.php
6161
:lines: 2-
6262

63-
Each of the "routes" is a 3 element array containing the HTTP verb (or "add" for all),
63+
Each of the "routes" is a 3 element array containing the uppercase HTTP verb (or "add" for all),
6464
the URI to match, and the routing destination.
6565

6666
.. _feature-setting-session-values:

user_guide_src/source/testing/feature/002.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$result = $this->call('GET', '/');
55

66
// Submit a form
7-
$result = $this->call('post', 'contact', [
7+
$result = $this->call('POST', 'contact', [
88
'name' => 'Fred Flintstone',
99
'email' => 'flintyfred@example.com',
1010
]);

0 commit comments

Comments
 (0)