Skip to content

Commit 92bab56

Browse files
committed
refactor: fix HTTP verbs for FeatureTestTrait::withRoutes()
1 parent 8a0ced0 commit 92bab56

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

system/Test/FeatureTestTrait.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trait FeatureTestTrait
3636
*
3737
* Example routes:
3838
* [
39-
* ['get', 'home', 'Home::index']
39+
* ['GET', 'home', 'Home::index'],
4040
* ]
4141
*
4242
* @param array|null $routes Array to set routes
@@ -51,10 +51,13 @@ protected function withRoutes(?array $routes = null)
5151
$collection->resetRoutes();
5252

5353
foreach ($routes as $route) {
54+
// @TODO For backward compatibility. Remove strtolower() in the future.
55+
$method = strtolower($route[0]);
56+
5457
if (isset($route[3])) {
55-
$collection->{$route[0]}($route[1], $route[2], $route[3]);
58+
$collection->{$method}($route[1], $route[2], $route[3]);
5659
} else {
57-
$collection->{$route[0]}($route[1], $route[2]);
60+
$collection->{$method}($route[1], $route[2]);
5861
}
5962
}
6063
}

tests/system/HomeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testPageLoadsSuccessfully(): void
2828
{
2929
$this->withRoutes([
3030
[
31-
'get',
31+
'GET',
3232
'home',
3333
'\App\Controllers\Home::index',
3434
],

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testCallGet(): void
4949
{
5050
$this->withRoutes([
5151
[
52-
'get',
52+
'GET',
5353
'home',
5454
static fn () => 'Hello World',
5555
],
@@ -69,7 +69,7 @@ public function testCallGetAndUriString(): void
6969
{
7070
$this->withRoutes([
7171
[
72-
'get',
72+
'GET',
7373
'foo/bar/1/2/3',
7474
static fn () => 'Hello World',
7575
],
@@ -85,7 +85,7 @@ public function testCallGetAndFilterReturnsResponse(): void
8585
{
8686
$this->withRoutes([
8787
[
88-
'get',
88+
'GET',
8989
'admin',
9090
static fn () => 'Admin Area',
9191
['filter' => 'test-redirectfilter'],
@@ -100,7 +100,7 @@ public function testClosureWithEcho()
100100
{
101101
$this->withRoutes([
102102
[
103-
'get',
103+
'GET',
104104
'home',
105105
static function () { echo 'test echo'; },
106106
],
@@ -118,7 +118,7 @@ public function testCallPost(): void
118118
{
119119
$this->withRoutes([
120120
[
121-
'post',
121+
'POST',
122122
'home',
123123
static fn () => 'Hello Mars',
124124
],
@@ -132,7 +132,7 @@ public function testCallPostWithBody(): void
132132
{
133133
$this->withRoutes([
134134
[
135-
'post',
135+
'POST',
136136
'home',
137137
static fn () => 'Hello ' . service('request')->getPost('foo') . '!',
138138
],
@@ -146,7 +146,7 @@ public function testCallValidationTwice(): void
146146
{
147147
$this->withRoutes([
148148
[
149-
'post',
149+
'POST',
150150
'section/create',
151151
static function () {
152152
$validation = Services::validation();
@@ -176,7 +176,7 @@ public function testCallPut(): void
176176
{
177177
$this->withRoutes([
178178
[
179-
'put',
179+
'PUT',
180180
'home',
181181
static fn () => 'Hello Pluto',
182182
],
@@ -190,7 +190,7 @@ public function testCallPatch(): void
190190
{
191191
$this->withRoutes([
192192
[
193-
'patch',
193+
'PATCH',
194194
'home',
195195
static fn () => 'Hello Jupiter',
196196
],
@@ -204,7 +204,7 @@ public function testCallOptions(): void
204204
{
205205
$this->withRoutes([
206206
[
207-
'options',
207+
'OPTIONS',
208208
'home',
209209
static fn () => 'Hello George',
210210
],
@@ -218,7 +218,7 @@ public function testCallDelete(): void
218218
{
219219
$this->withRoutes([
220220
[
221-
'delete',
221+
'DELETE',
222222
'home',
223223
static fn () => 'Hello Wonka',
224224
],
@@ -232,7 +232,7 @@ public function testSession(): void
232232
{
233233
$response = $this->withRoutes([
234234
[
235-
'get',
235+
'GET',
236236
'home',
237237
static fn () => 'Home',
238238
],
@@ -254,7 +254,7 @@ public function testWithSessionNull(): void
254254

255255
$response = $this->withRoutes([
256256
[
257-
'get',
257+
'GET',
258258
'home',
259259
static fn () => 'Home',
260260
],
@@ -268,7 +268,7 @@ public function testReturns(): void
268268
{
269269
$this->withRoutes([
270270
[
271-
'get',
271+
'GET',
272272
'home',
273273
'\Tests\Support\Controllers\Popcorn::index',
274274
],
@@ -281,7 +281,7 @@ public function testIgnores(): void
281281
{
282282
$this->withRoutes([
283283
[
284-
'get',
284+
'GET',
285285
'home',
286286
'\Tests\Support\Controllers\Popcorn::cat',
287287
],
@@ -294,7 +294,7 @@ public function testEchoesWithParams(): void
294294
{
295295
$this->withRoutes([
296296
[
297-
'get',
297+
'GET',
298298
'home',
299299
'\Tests\Support\Controllers\Popcorn::canyon',
300300
],
@@ -308,7 +308,7 @@ public function testEchoesWithQuery(): void
308308
{
309309
$this->withRoutes([
310310
[
311-
'get',
311+
'GET',
312312
'home',
313313
'\Tests\Support\Controllers\Popcorn::canyon',
314314
],
@@ -373,7 +373,7 @@ public function testOpenCliRoutesFromHttpGot404($from, $to, $httpGet): void
373373

374374
$this->withRoutes([
375375
[
376-
'cli',
376+
'CLI',
377377
$from,
378378
$to,
379379
],
@@ -388,7 +388,7 @@ public function testIsOkWithRedirects(): void
388388
{
389389
$this->withRoutes([
390390
[
391-
'get',
391+
'GET',
392392
'home',
393393
'\Tests\Support\Controllers\Popcorn::goaway',
394394
],
@@ -402,7 +402,7 @@ public function testCallGetWithParams(): void
402402
{
403403
$this->withRoutes([
404404
[
405-
'get',
405+
'GET',
406406
'home',
407407
static fn () => json_encode(Services::request()->getGet()),
408408
],
@@ -429,7 +429,7 @@ public function testCallGetWithParamsAndREQUEST(): void
429429
{
430430
$this->withRoutes([
431431
[
432-
'get',
432+
'GET',
433433
'home',
434434
static fn () => json_encode(Services::request()->fetchGlobal('request')),
435435
],
@@ -456,7 +456,7 @@ public function testCallPostWithParams(): void
456456
{
457457
$this->withRoutes([
458458
[
459-
'post',
459+
'POST',
460460
'home',
461461
static fn () => json_encode(Services::request()->getPost()),
462462
],
@@ -483,7 +483,7 @@ public function testCallPostWithParamsAndREQUEST(): void
483483
{
484484
$this->withRoutes([
485485
[
486-
'post',
486+
'POST',
487487
'home',
488488
static fn () => json_encode(Services::request()->fetchGlobal('request')),
489489
],
@@ -510,7 +510,7 @@ public function testCallPutWithJsonRequest(): void
510510
{
511511
$this->withRoutes([
512512
[
513-
'put',
513+
'PUT',
514514
'home',
515515
'\Tests\Support\Controllers\Popcorn::echoJson',
516516
],
@@ -534,7 +534,7 @@ public function testCallPutWithJsonRequestAndREQUEST(): void
534534
{
535535
$this->withRoutes([
536536
[
537-
'put',
537+
'PUT',
538538
'home',
539539
static fn () => json_encode(Services::request()->fetchGlobal('request')),
540540
],
@@ -558,7 +558,7 @@ public function testCallWithJsonRequest(): void
558558
{
559559
$this->withRoutes([
560560
[
561-
'post',
561+
'POST',
562562
'home',
563563
'\Tests\Support\Controllers\Popcorn::echoJson',
564564
],

user_guide_src/source/testing/feature/002.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
// Get a simple page
4-
$result = $this->call('get', '/');
4+
$result = $this->call('GET', '/');
55

66
// Submit a form
77
$result = $this->call('post', 'contact', [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
$routes = [
4-
['get', 'users', 'UserController::list'],
4+
['GET', 'users', 'UserController::list'],
55
];
66

77
$result = $this->withRoutes($routes)->get('users');

0 commit comments

Comments
 (0)