Skip to content

Commit b3f30cc

Browse files
committed
test: fix the test cases error.
1 parent 29b7f8c commit b3f30cc

File tree

6 files changed

+150
-17
lines changed

6 files changed

+150
-17
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter\Router\Controllers;
13+
14+
use CodeIgniter\Controller;
15+
16+
class Admin_user extends Controller
17+
{
18+
public function show_list(): void
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter\Router\Controllers;
13+
14+
use CodeIgniter\Controller;
15+
16+
class Test extends Controller
17+
{
18+
public function test(): void
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter\Router\Controllers\foo\bar\baz;
13+
14+
use CodeIgniter\Controller;
15+
16+
class Some_controller extends Controller
17+
{
18+
public function some_method($first = ''): void
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter\Router\Controllers;
13+
14+
use CodeIgniter\Controller;
15+
16+
class Φ extends Controller
17+
{
18+
public function getIndex(): void
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter\Router\Controllers\Φ;
13+
14+
use CodeIgniter\Controller;
15+
16+
class Home extends Controller
17+
{
18+
public function getIndex(): void
19+
{
20+
}
21+
}

tests/system/Router/RouterTest.php

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,12 @@ public function testAutoRouteFindsDefaultControllerAndMethod(): void
201201
$this->collection->setDefaultMethod('test');
202202
$router = new Router($this->collection, $this->request);
203203

204+
copy(TESTPATH . 'system/Router/Controllers/Test.php', APPPATH . 'Controllers/Test.php');
205+
204206
$router->autoRoute('/');
205207

208+
unlink(APPPATH . 'Controllers/Test.php');
209+
206210
$this->assertSame('Test', $router->controllerName());
207211
$this->assertSame('test', $router->methodName());
208212
}
@@ -212,9 +216,9 @@ public function testAutoRouteFindsControllerWithFileAndMethod(): void
212216
$this->collection->setAutoRoute(true);
213217
$router = new Router($this->collection, $this->request);
214218

215-
copy(TESTPATH . 'system/Router/Controllers/MyController.php', APPPATH . 'Controllers/Mycontroller.php');
219+
copy(TESTPATH . 'system/Router/Controllers/Mycontroller.php', APPPATH . 'Controllers/Mycontroller.php');
216220

217-
$router->autoRoute('Mycontroller/getSomemethod');
221+
$router->autoRoute('mycontroller/getSomemethod');
218222

219223
unlink(APPPATH . 'Controllers/Mycontroller.php');
220224

@@ -227,7 +231,7 @@ public function testAutoRouteFindsControllerWithFile(): void
227231
$this->collection->setAutoRoute(true);
228232
$router = new Router($this->collection, $this->request);
229233

230-
copy(TESTPATH . 'system/Router/Controllers/MyController.php', APPPATH . 'Controllers/Mycontroller.php');
234+
copy(TESTPATH . 'system/Router/Controllers/Mycontroller.php', APPPATH . 'Controllers/Mycontroller.php');
231235

232236
$router->autoRoute('mycontroller');
233237

@@ -244,9 +248,9 @@ public function testAutoRouteFindsControllerWithSubfolder(): void
244248

245249
mkdir(APPPATH . 'Controllers/Subfolder');
246250

247-
copy(TESTPATH . 'system/Router/Controllers/Subfolder/MyController.php', APPPATH . 'Controllers/Subfolder/Mycontroller.php');
251+
copy(TESTPATH . 'system/Router/Controllers/Subfolder/Mycontroller.php', APPPATH . 'Controllers/Subfolder/Mycontroller.php');
248252

249-
$router->autoRoute('subfolder/Mycontroller/getSomemethod');
253+
$router->autoRoute('subfolder/mycontroller/getSomemethod');
250254

251255
unlink(APPPATH . 'Controllers/Subfolder/Mycontroller.php');
252256

@@ -263,9 +267,11 @@ public function testAutoRouteFindsDashedSubfolder(): void
263267
$router->setTranslateURIDashes(true);
264268

265269
mkdir(APPPATH . 'Controllers/Dash_folder');
270+
copy(TESTPATH . 'system/Router/Controllers/Dash_folder/Mycontroller.php', APPPATH . 'Controllers/Dash_folder/Mycontroller.php');
266271

267272
$router->autoRoute('dash-folder/mycontroller/somemethod');
268273

274+
unlink(APPPATH . 'Controllers/Dash_folder/Mycontroller.php');
269275
rmdir(APPPATH . 'Controllers/Dash_folder');
270276

271277
$this->assertSame('Dash_folder/', $router->directory());
@@ -280,16 +286,16 @@ public function testAutoRouteFindsDashedController(): void
280286
$router->setTranslateURIDashes(true);
281287

282288
mkdir(APPPATH . 'Controllers/Dash_folder');
283-
file_put_contents(APPPATH . 'Controllers/Dash_folder/Dash_controller.php', '');
289+
copy(TESTPATH . 'system/Router/Controllers/Dash_folder/Dash_controller.php', APPPATH . 'Controllers/Dash_folder/Dash_controller.php');
284290

285-
$router->autoRoute('dash-folder/dash-controller/somemethod');
291+
$router->autoRoute('dash-folder/dash-controller/getSomemethod');
286292

287293
unlink(APPPATH . 'Controllers/Dash_folder/Dash_controller.php');
288294
rmdir(APPPATH . 'Controllers/Dash_folder');
289295

290296
$this->assertSame('Dash_folder/', $router->directory());
291297
$this->assertSame('Dash_controller', $router->controllerName());
292-
$this->assertSame('somemethod', $router->methodName());
298+
$this->assertSame('getSomemethod', $router->methodName());
293299
}
294300

295301
public function testAutoRouteFindsDashedMethod(): void
@@ -299,16 +305,16 @@ public function testAutoRouteFindsDashedMethod(): void
299305
$router->setTranslateURIDashes(true);
300306

301307
mkdir(APPPATH . 'Controllers/Dash_folder');
302-
file_put_contents(APPPATH . 'Controllers/Dash_folder/Dash_controller.php', '');
308+
copy(TESTPATH . 'system/Router/Controllers/Dash_folder/Dash_controller.php', APPPATH . 'Controllers/Dash_folder/Dash_controller.php');
303309

304-
$router->autoRoute('dash-folder/dash-controller/dash-method');
310+
$router->autoRoute('dash-folder/dash-controller/getDash_method');
305311

306312
unlink(APPPATH . 'Controllers/Dash_folder/Dash_controller.php');
307313
rmdir(APPPATH . 'Controllers/Dash_folder');
308314

309315
$this->assertSame('Dash_folder/', $router->directory());
310316
$this->assertSame('Dash_controller', $router->controllerName());
311-
$this->assertSame('dash_method', $router->methodName());
317+
$this->assertSame('getDash_method', $router->methodName());
312318
}
313319

314320
public function testAutoRouteFindsDefaultDashFolder(): void
@@ -318,9 +324,11 @@ public function testAutoRouteFindsDefaultDashFolder(): void
318324
$router->setTranslateURIDashes(true);
319325

320326
mkdir(APPPATH . 'Controllers/Dash_folder');
327+
copy(TESTPATH . 'system/Router/Controllers/Dash_folder/Home.php', APPPATH . 'Controllers/Dash_folder/Home.php');
321328

322329
$router->autoRoute('dash-folder');
323330

331+
unlink(APPPATH . 'Controllers/Dash_folder/Home.php');
324332
rmdir(APPPATH . 'Controllers/Dash_folder');
325333

326334
$this->assertSame('Dash_folder/', $router->directory());
@@ -335,9 +343,11 @@ public function testAutoRouteFindsMByteDir(): void
335343
$router->setTranslateURIDashes(true);
336344

337345
mkdir(APPPATH . 'Controllers/Φ');
346+
copy(TESTPATH . 'system/Router/Controllers/Φ/Home.php', APPPATH . 'Controllers/Φ/Home.php');
338347

339348
$router->autoRoute('Φ');
340349

350+
unlink(APPPATH . 'Controllers/Φ/Home.php');
341351
rmdir(APPPATH . 'Controllers/Φ');
342352

343353
$this->assertSame('Φ/', $router->directory());
@@ -351,11 +361,11 @@ public function testAutoRouteFindsMByteController(): void
351361
$router = new Router($this->collection, $this->request);
352362
$router->setTranslateURIDashes(true);
353363

354-
file_put_contents(APPPATH . 'Controllers/Φ', '');
364+
copy(TESTPATH . 'system/Router/Controllers/Φ.php', APPPATH . 'Controllers/Φ.php');
355365

356366
$router->autoRoute('Φ');
357367

358-
unlink(APPPATH . 'Controllers/Φ');
368+
unlink(APPPATH . 'Controllers/Φ.php');
359369

360370
$this->assertSame('Φ', $router->controllerName());
361371
$this->assertSame('index', $router->methodName());
@@ -749,7 +759,11 @@ public function testTranslateURIDashesForAutoRoute(): void
749759
$router = new Router($this->collection, $this->request);
750760
$router->setTranslateURIDashes(true);
751761

752-
$router->autoRoute('admin-user/show-list');
762+
copy(TESTPATH . 'system/Router/Controllers/Admin_user.php', APPPATH . 'Controllers/Admin_user.php');
763+
764+
$router->autoRoute('admin_user/show_list');
765+
766+
unlink(APPPATH . 'Controllers/Admin_user.php');
753767

754768
$this->assertSame('Admin_user', $router->controllerName());
755769
$this->assertSame('show_list', $router->methodName());
@@ -763,10 +777,14 @@ public function testAutoRouteMatchesZeroParams(): void
763777
$this->collection->setAutoRoute(true);
764778
$router = new Router($this->collection, $this->request);
765779

766-
$router->autoRoute('myController/someMethod/0/abc');
780+
copy(TESTPATH . 'system/Router/Controllers/Mycontroller.php', APPPATH . 'Controllers/Mycontroller.php');
767781

768-
$this->assertSame('MyController', $router->controllerName());
769-
$this->assertSame('someMethod', $router->methodName());
782+
$router->autoRoute('mycontroller/getSomemethod/0/abc');
783+
784+
$this->assertSame('Mycontroller', $router->controllerName());
785+
$this->assertSame('getSomemethod', $router->methodName());
786+
787+
unlink(APPPATH . 'Controllers/Mycontroller.php');
770788

771789
$expected = [
772790
'0',
@@ -834,9 +852,19 @@ public function testRouterPriorDirectory(): void
834852
$this->collection->setAutoRoute(true);
835853
$router = new Router($this->collection, $this->request);
836854

855+
mkdir(APPPATH . 'Controllers/foo');
856+
mkdir(APPPATH . 'Controllers/foo/bar');
857+
mkdir(APPPATH . 'Controllers/foo/bar/baz');
858+
copy(TESTPATH . 'system/Router/Controllers/foo/bar/baz/Some_controller.php', APPPATH . 'Controllers/foo/bar/baz/Some_controller.php');
859+
837860
$router->setDirectory('foo/bar/baz', false, true);
838861
$router->handle('Some_controller/some_method/param1/param2/param3');
839862

863+
unlink(APPPATH . 'Controllers/foo/bar/baz/Some_controller.php');
864+
rmdir(APPPATH . 'Controllers/foo/bar/baz');
865+
rmdir(APPPATH . 'Controllers/foo/bar');
866+
rmdir(APPPATH . 'Controllers/foo');
867+
840868
$this->assertSame('foo/bar/baz/', $router->directory());
841869
$this->assertSame('Some_controller', $router->controllerName());
842870
$this->assertSame('some_method', $router->methodName());

0 commit comments

Comments
 (0)