Skip to content

Commit 30fd7dc

Browse files
authored
refactor: use uppercase HTTP method names in FeatureTestTrait (#10003)
1 parent 2a6daf9 commit 30fd7dc

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

system/Test/FeatureTestTrait.php

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

7171
foreach ($routes as $route) {
72-
if ($route[0] === strtolower($route[0])) {
73-
@trigger_error(
74-
'Passing lowercase HTTP method "' . $route[0] . '" is deprecated.'
75-
. ' Use uppercase HTTP method like "' . strtoupper($route[0]) . '".',
76-
E_USER_DEPRECATED,
77-
);
78-
}
79-
80-
// @todo v4.7.1 Remove the strtoupper() and use 'add' in v4.8.0
81-
if (! in_array(strtoupper($route[0]), ['ADD', 'CLI', ...Method::all()], true)) {
72+
if (! in_array($route[0], ['add', 'CLI', ...Method::all()], true)) {
8273
throw new RuntimeException(sprintf(
8374
'Invalid HTTP method "%s" provided for route "%s".',
8475
$route[0],
@@ -179,26 +170,12 @@ public function skipEvents()
179170
* Calls a single URI, executes it, and returns a TestResponse
180171
* instance that can be used to run many assertions against.
181172
*
182-
* @param string $method HTTP verb
173+
* @param uppercase-string $method HTTP verb
183174
*
184175
* @return TestResponse
185176
*/
186177
public function call(string $method, string $path, ?array $params = null)
187178
{
188-
if ($method === strtolower($method)) {
189-
@trigger_error(
190-
'Passing lowercase HTTP method "' . $method . '" is deprecated.'
191-
. ' Use uppercase HTTP method like "' . strtoupper($method) . '".',
192-
E_USER_DEPRECATED,
193-
);
194-
}
195-
196-
/**
197-
* @deprecated 4.5.0
198-
* @TODO remove this in the future.
199-
*/
200-
$method = strtoupper($method);
201-
202179
// Simulate having a blank session
203180
$_SESSION = [];
204181
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
@@ -27,6 +27,9 @@ Behavior Changes
2727
- **Database:** The Postgre driver's ``$db->error()['code']`` previously always returned ``''``. It now returns the 5-character SQLSTATE string for query and transaction failures (e.g., ``'42P01'``), or ``'08006'`` for connection-level failures. Code that relied on ``$db->error()['code'] === ''`` will need updating.
2828
- **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method
2929
(e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match.
30+
- **Testing:** Tests using the ``FeatureTestTrait`` must now use uppercase HTTP method names when performing a request when using the ``call()`` method directly
31+
(e.g., ``$this->call('GET', '/path')`` instead of ``$this->call('get', '/path')``). Additionally, setting method-based routes using ``withRoutes()`` must
32+
also use uppercase method names (e.g., ``$this->withRoutes([['GET', 'home', 'Home::index']])``).
3033

3134
Interface Changes
3235
=================

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)