Skip to content

Commit 25e3ad2

Browse files
committed
test: update test code with RouteCollection::getRoutes()
1 parent 5b10fa8 commit 25e3ad2

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tests/Unit/AuthRoutesTest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Tests\Unit;
1515

16+
use CodeIgniter\CodeIgniter;
17+
use CodeIgniter\Router\RouteCollection;
18+
use CodeIgniter\Shield\Auth;
1619
use Tests\Support\TestCase;
1720

1821
/**
@@ -22,12 +25,18 @@ final class AuthRoutesTest extends TestCase
2225
{
2326
public function testRoutes(): void
2427
{
28+
/** @var RouteCollection $collection */
2529
$collection = single_service('routes');
26-
$auth = service('auth');
30+
/** @var Auth $auth */
31+
$auth = service('auth');
2732

2833
$auth->routes($collection);
2934

30-
$routes = $collection->getRoutes('get');
35+
if (version_compare(CodeIgniter::CI_VERSION, '4.5') >= 0) {
36+
$routes = $collection->getRoutes('GET');
37+
} else {
38+
$routes = $collection->getRoutes('get');
39+
}
3140

3241
$this->assertArrayHasKey('register', $routes);
3342
$this->assertArrayHasKey('login', $routes);
@@ -43,7 +52,11 @@ public function testRoutesExcept(): void
4352

4453
$auth->routes($collection, ['except' => ['login']]);
4554

46-
$routes = $collection->getRoutes('get');
55+
if (version_compare(CodeIgniter::CI_VERSION, '4.5') >= 0) {
56+
$routes = $collection->getRoutes('GET');
57+
} else {
58+
$routes = $collection->getRoutes('get');
59+
}
4760

4861
$this->assertArrayNotHasKey('login', $routes);
4962
$this->assertArrayHasKey('register', $routes);
@@ -59,7 +72,11 @@ public function testRoutesCustomNamespace(): void
5972

6073
$auth->routes($collection, ['namespace' => 'Auth']);
6174

62-
$routes = $collection->getRoutes('get');
75+
if (version_compare(CodeIgniter::CI_VERSION, '4.5') >= 0) {
76+
$routes = $collection->getRoutes('GET');
77+
} else {
78+
$routes = $collection->getRoutes('get');
79+
}
6380

6481
$this->assertSame('\Auth\RegisterController::registerView', $routes['register']);
6582
}

0 commit comments

Comments
 (0)