Skip to content

Commit a18869b

Browse files
committed
test: use HTTP\Method
1 parent c1678b7 commit a18869b

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

tests/system/Router/AutoRouterImprovedTest.php

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\Config\Factories;
1717
use CodeIgniter\Config\Services;
1818
use CodeIgniter\Exceptions\PageNotFoundException;
19+
use CodeIgniter\HTTP\Method;
1920
use CodeIgniter\Router\Controllers\Dash_folder\Dash_controller;
2021
use CodeIgniter\Router\Controllers\Dash_folder\Home;
2122
use CodeIgniter\Router\Controllers\Index;
@@ -60,7 +61,7 @@ public function testAutoRouteFindsDefaultControllerAndMethodGet(): void
6061
$router = $this->createNewAutoRouter();
6162

6263
[$directory, $controller, $method, $params]
63-
= $router->getRoute('/', 'GET');
64+
= $router->getRoute('/', Method::GET);
6465

6566
$this->assertNull($directory);
6667
$this->assertSame('\\' . Index::class, $controller);
@@ -86,7 +87,7 @@ public function testAutoRouteFindsModuleDefaultControllerAndMethodGet()
8687
$router = $this->createNewAutoRouter('App/Controllers');
8788

8889
[$directory, $controller, $method, $params]
89-
= $router->getRoute('test', 'GET');
90+
= $router->getRoute('test', Method::GET);
9091

9192
$this->assertNull($directory);
9293
$this->assertSame('\\' . Index::class, $controller);
@@ -101,7 +102,7 @@ public function testAutoRouteFindsDefaultControllerAndMethodPost(): void
101102
$router = $this->createNewAutoRouter();
102103

103104
[$directory, $controller, $method, $params]
104-
= $router->getRoute('/', 'POST');
105+
= $router->getRoute('/', Method::POST);
105106

106107
$this->assertNull($directory);
107108
$this->assertSame('\\' . Index::class, $controller);
@@ -114,7 +115,7 @@ public function testAutoRouteFindsControllerWithFileAndMethod(): void
114115
$router = $this->createNewAutoRouter();
115116

116117
[$directory, $controller, $method, $params]
117-
= $router->getRoute('mycontroller/somemethod', 'GET');
118+
= $router->getRoute('mycontroller/somemethod', Method::GET);
118119

119120
$this->assertNull($directory);
120121
$this->assertSame('\\' . Mycontroller::class, $controller);
@@ -132,7 +133,7 @@ public function testFindsControllerAndMethodAndParam(): void
132133
$router = $this->createNewAutoRouter();
133134

134135
[$directory, $controller, $method, $params]
135-
= $router->getRoute('mycontroller/somemethod/a', 'GET');
136+
= $router->getRoute('mycontroller/somemethod/a', Method::GET);
136137

137138
$this->assertNull($directory);
138139
$this->assertSame('\\' . Mycontroller::class, $controller);
@@ -154,15 +155,15 @@ public function testUriParamCountIsGreaterThanMethodParams(): void
154155

155156
$router = $this->createNewAutoRouter();
156157

157-
$router->getRoute('mycontroller/somemethod/a/b', 'GET');
158+
$router->getRoute('mycontroller/somemethod/a/b', Method::GET);
158159
}
159160

160161
public function testAutoRouteFindsControllerWithFile(): void
161162
{
162163
$router = $this->createNewAutoRouter();
163164

164165
[$directory, $controller, $method, $params]
165-
= $router->getRoute('mycontroller', 'GET');
166+
= $router->getRoute('mycontroller', Method::GET);
166167

167168
$this->assertNull($directory);
168169
$this->assertSame('\\' . Mycontroller::class, $controller);
@@ -175,7 +176,7 @@ public function testAutoRouteFindsControllerWithSubfolder(): void
175176
$router = $this->createNewAutoRouter();
176177

177178
[$directory, $controller, $method, $params]
178-
= $router->getRoute('subfolder/mycontroller/somemethod', 'GET');
179+
= $router->getRoute('subfolder/mycontroller/somemethod', Method::GET);
179180

180181
$this->assertSame('Subfolder/', $directory);
181182
$this->assertSame('\\' . \CodeIgniter\Router\Controllers\Subfolder\Mycontroller::class, $controller);
@@ -193,7 +194,7 @@ public function testAutoRouteFindsControllerWithSubSubfolder()
193194
$router = $this->createNewAutoRouter();
194195

195196
[$directory, $controller, $method, $params]
196-
= $router->getRoute('subfolder/sub/mycontroller/somemethod', 'GET');
197+
= $router->getRoute('subfolder/sub/mycontroller/somemethod', Method::GET);
197198

198199
$this->assertSame('Subfolder/Sub/', $directory);
199200
$this->assertSame('\\' . \CodeIgniter\Router\Controllers\Subfolder\Sub\Mycontroller::class, $controller);
@@ -206,7 +207,7 @@ public function testAutoRouteFindsDashedSubfolder(): void
206207
$router = $this->createNewAutoRouter();
207208

208209
[$directory, $controller, $method, $params]
209-
= $router->getRoute('dash-folder/mycontroller/somemethod', 'GET');
210+
= $router->getRoute('dash-folder/mycontroller/somemethod', Method::GET);
210211

211212
$this->assertSame('Dash_folder/', $directory);
212213
$this->assertSame(
@@ -222,7 +223,7 @@ public function testAutoRouteFindsDashedController(): void
222223
$router = $this->createNewAutoRouter();
223224

224225
[$directory, $controller, $method, $params]
225-
= $router->getRoute('dash-folder/dash-controller/somemethod', 'GET');
226+
= $router->getRoute('dash-folder/dash-controller/somemethod', Method::GET);
226227

227228
$this->assertSame('Dash_folder/', $directory);
228229
$this->assertSame('\\' . Dash_controller::class, $controller);
@@ -235,7 +236,7 @@ public function testAutoRouteFindsDashedMethod(): void
235236
$router = $this->createNewAutoRouter();
236237

237238
[$directory, $controller, $method, $params]
238-
= $router->getRoute('dash-folder/dash-controller/dash-method', 'GET');
239+
= $router->getRoute('dash-folder/dash-controller/dash-method', Method::GET);
239240

240241
$this->assertSame('Dash_folder/', $directory);
241242
$this->assertSame('\\' . Dash_controller::class, $controller);
@@ -248,7 +249,7 @@ public function testAutoRouteFindsDefaultDashFolder(): void
248249
$router = $this->createNewAutoRouter();
249250

250251
[$directory, $controller, $method, $params]
251-
= $router->getRoute('dash-folder', 'GET');
252+
= $router->getRoute('dash-folder', Method::GET);
252253

253254
$this->assertSame('Dash_folder/', $directory);
254255
$this->assertSame('\\' . Home::class, $controller);
@@ -261,7 +262,7 @@ public function testAutoRouteFallbackToDefaultMethod()
261262
$router = $this->createNewAutoRouter();
262263

263264
[$directory, $controller, $method, $params]
264-
= $router->getRoute('index/15', 'GET');
265+
= $router->getRoute('index/15', Method::GET);
265266

266267
$this->assertNull($directory);
267268
$this->assertSame('\\' . Index::class, $controller);
@@ -279,7 +280,7 @@ public function testAutoRouteFallbackToDefaultControllerOneParam()
279280
$router = $this->createNewAutoRouter();
280281

281282
[$directory, $controller, $method, $params]
282-
= $router->getRoute('subfolder/15', 'GET');
283+
= $router->getRoute('subfolder/15', Method::GET);
283284

284285
$this->assertSame('Subfolder/', $directory);
285286
$this->assertSame('\\' . \CodeIgniter\Router\Controllers\Subfolder\Home::class, $controller);
@@ -297,7 +298,7 @@ public function testAutoRouteFallbackToDefaultControllerTwoParams()
297298
$router = $this->createNewAutoRouter();
298299

299300
[$directory, $controller, $method, $params]
300-
= $router->getRoute('subfolder/15/20', 'GET');
301+
= $router->getRoute('subfolder/15/20', Method::GET);
301302

302303
$this->assertSame('Subfolder/', $directory);
303304
$this->assertSame('\\' . \CodeIgniter\Router\Controllers\Subfolder\Home::class, $controller);
@@ -315,7 +316,7 @@ public function testAutoRouteFallbackToDefaultControllerNoParams()
315316
$router = $this->createNewAutoRouter();
316317

317318
[$directory, $controller, $method, $params]
318-
= $router->getRoute('subfolder', 'GET');
319+
= $router->getRoute('subfolder', Method::GET);
319320

320321
$this->assertSame('Subfolder/', $directory);
321322
$this->assertSame('\\' . \CodeIgniter\Router\Controllers\Subfolder\Home::class, $controller);
@@ -334,7 +335,7 @@ public function testAutoRouteRejectsSingleDot(): void
334335

335336
$router = $this->createNewAutoRouter();
336337

337-
$router->getRoute('.', 'GET');
338+
$router->getRoute('.', Method::GET);
338339
}
339340

340341
public function testAutoRouteRejectsDoubleDot(): void
@@ -343,7 +344,7 @@ public function testAutoRouteRejectsDoubleDot(): void
343344

344345
$router = $this->createNewAutoRouter();
345346

346-
$router->getRoute('..', 'GET');
347+
$router->getRoute('..', Method::GET);
347348
}
348349

349350
public function testAutoRouteRejectsMidDot(): void
@@ -352,7 +353,7 @@ public function testAutoRouteRejectsMidDot(): void
352353

353354
$router = $this->createNewAutoRouter();
354355

355-
$router->getRoute('foo.bar', 'GET');
356+
$router->getRoute('foo.bar', Method::GET);
356357
}
357358

358359
public function testRejectsDefaultControllerPath(): void
@@ -361,7 +362,7 @@ public function testRejectsDefaultControllerPath(): void
361362

362363
$router = $this->createNewAutoRouter();
363364

364-
$router->getRoute('home', 'GET');
365+
$router->getRoute('home', Method::GET);
365366
}
366367

367368
public function testRejectsDefaultControllerAndDefaultMethodPath(): void
@@ -370,7 +371,7 @@ public function testRejectsDefaultControllerAndDefaultMethodPath(): void
370371

371372
$router = $this->createNewAutoRouter();
372373

373-
$router->getRoute('home/index', 'GET');
374+
$router->getRoute('home/index', Method::GET);
374375
}
375376

376377
public function testRejectsDefaultMethodPath(): void
@@ -379,7 +380,7 @@ public function testRejectsDefaultMethodPath(): void
379380

380381
$router = $this->createNewAutoRouter();
381382

382-
$router->getRoute('mycontroller/index', 'GET');
383+
$router->getRoute('mycontroller/index', Method::GET);
383384
}
384385

385386
public function testRejectsControllerWithRemapMethod(): void
@@ -391,7 +392,7 @@ public function testRejectsControllerWithRemapMethod(): void
391392

392393
$router = $this->createNewAutoRouter();
393394

394-
$router->getRoute('remap/test', 'GET');
395+
$router->getRoute('remap/test', Method::GET);
395396
}
396397

397398
public function testRejectsURIWithUnderscoreFolder()
@@ -403,7 +404,7 @@ public function testRejectsURIWithUnderscoreFolder()
403404

404405
$router = $this->createNewAutoRouter();
405406

406-
$router->getRoute('dash_folder', 'GET');
407+
$router->getRoute('dash_folder', Method::GET);
407408
}
408409

409410
public function testRejectsURIWithUnderscoreController()
@@ -415,7 +416,7 @@ public function testRejectsURIWithUnderscoreController()
415416

416417
$router = $this->createNewAutoRouter();
417418

418-
$router->getRoute('dash-folder/dash_controller/dash-method', 'GET');
419+
$router->getRoute('dash-folder/dash_controller/dash-method', Method::GET);
419420
}
420421

421422
public function testRejectsURIWithUnderscoreMethod()
@@ -427,15 +428,15 @@ public function testRejectsURIWithUnderscoreMethod()
427428

428429
$router = $this->createNewAutoRouter();
429430

430-
$router->getRoute('dash-folder/dash-controller/dash_method', 'GET');
431+
$router->getRoute('dash-folder/dash-controller/dash_method', Method::GET);
431432
}
432433

433434
public function testPermitsURIWithUnderscoreParam()
434435
{
435436
$router = $this->createNewAutoRouter();
436437

437438
[$directory, $controller, $method, $params]
438-
= $router->getRoute('mycontroller/somemethod/a_b', 'GET');
439+
= $router->getRoute('mycontroller/somemethod/a_b', Method::GET);
439440

440441
$this->assertNull($directory);
441442
$this->assertSame('\\' . Mycontroller::class, $controller);
@@ -448,7 +449,7 @@ public function testDoesNotTranslateDashInParam()
448449
$router = $this->createNewAutoRouter();
449450

450451
[$directory, $controller, $method, $params]
451-
= $router->getRoute('mycontroller/somemethod/a-b', 'GET');
452+
= $router->getRoute('mycontroller/somemethod/a-b', Method::GET);
452453

453454
$this->assertNull($directory);
454455
$this->assertSame('\\' . Mycontroller::class, $controller);

0 commit comments

Comments
 (0)