Skip to content

Commit 3a7894c

Browse files
committed
test: add folders and move test files
1 parent 8c507cf commit 3a7894c

File tree

5 files changed

+51
-51
lines changed

5 files changed

+51
-51
lines changed

tests/Authentication/AccessTokenAuthenticatorTest.php renamed to tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\Authentication;
3+
namespace Tests\Authentication\Authenticators;
44

55
use CodeIgniter\I18n\Time;
66
use CodeIgniter\Shield\Authentication\Authentication;
@@ -28,7 +28,7 @@ protected function setUp(): void
2828

2929
$config = new Auth();
3030
$auth = new Authentication($config);
31-
$auth->setProvider(model(UserModel::class)); // @phpstan-ignore-line
31+
$auth->setProvider(\model(UserModel::class)); // @phpstan-ignore-line
3232

3333
/** @var AccessTokens $authenticator */
3434
$authenticator = $auth->factory('tokens');
@@ -39,7 +39,7 @@ protected function setUp(): void
3939

4040
public function testLogin()
4141
{
42-
$user = fake(UserModel::class);
42+
$user = \fake(UserModel::class);
4343

4444
$this->auth->login($user);
4545

@@ -51,7 +51,7 @@ public function testLogin()
5151
public function testLogout()
5252
{
5353
// this one's a little odd since it's stateless, but roll with it...
54-
$user = fake(UserModel::class);
54+
$user = \fake(UserModel::class);
5555

5656
$this->auth->login($user);
5757
$this->assertNotNull($this->auth->getUser());
@@ -62,7 +62,7 @@ public function testLogout()
6262

6363
public function testLoginByIdNoToken()
6464
{
65-
$user = fake(UserModel::class);
65+
$user = \fake(UserModel::class);
6666

6767
$this->assertFalse($this->auth->loggedIn());
6868

@@ -75,7 +75,7 @@ public function testLoginByIdNoToken()
7575
public function testLoginByIdWithToken()
7676
{
7777
/** @var User $user */
78-
$user = fake(UserModel::class);
78+
$user = \fake(UserModel::class);
7979
$token = $user->generateAccessToken('foo');
8080

8181
$this->setRequestHeader($token->raw_token);
@@ -90,7 +90,7 @@ public function testLoginByIdWithToken()
9090
public function testLoginByIdWithMultipleTokens()
9191
{
9292
/** @var User $user */
93-
$user = fake(UserModel::class);
93+
$user = \fake(UserModel::class);
9494
$token1 = $user->generateAccessToken('foo');
9595
$user->generateAccessToken('bar');
9696

@@ -108,37 +108,37 @@ public function testCheckNoToken()
108108
$result = $this->auth->check([]);
109109

110110
$this->assertFalse($result->isOK());
111-
$this->assertSame(lang('Auth.noToken'), $result->reason());
111+
$this->assertSame(\lang('Auth.noToken'), $result->reason());
112112
}
113113

114114
public function testCheckBadToken()
115115
{
116116
$result = $this->auth->check(['token' => 'abc123']);
117117

118118
$this->assertFalse($result->isOK());
119-
$this->assertSame(lang('Auth.badToken'), $result->reason());
119+
$this->assertSame(\lang('Auth.badToken'), $result->reason());
120120
}
121121

122122
public function testCheckOldToken()
123123
{
124124
/** @var User $user */
125-
$user = fake(UserModel::class);
125+
$user = \fake(UserModel::class);
126126
/** @var UserIdentityModel $identities */
127-
$identities = model(UserIdentityModel::class);
127+
$identities = \model(UserIdentityModel::class);
128128
$token = $user->generateAccessToken('foo');
129129
$token->last_used_at = Time::now()->subYears(1)->subMinutes(1);
130130
$identities->save($token);
131131

132132
$result = $this->auth->check(['token' => $token->raw_token]);
133133

134134
$this->assertFalse($result->isOK());
135-
$this->assertSame(lang('Auth.oldToken'), $result->reason());
135+
$this->assertSame(\lang('Auth.oldToken'), $result->reason());
136136
}
137137

138138
public function testCheckSuccess()
139139
{
140140
/** @var User $user */
141-
$user = fake(UserModel::class);
141+
$user = \fake(UserModel::class);
142142
$token = $user->generateAccessToken('foo');
143143

144144
$this->seeInDatabase('auth_identities', [
@@ -165,7 +165,7 @@ public function testAttemptCannotFindUser()
165165

166166
$this->assertInstanceOf(Result::class, $result);
167167
$this->assertFalse($result->isOK());
168-
$this->assertSame(lang('Auth.badToken'), $result->reason());
168+
$this->assertSame(\lang('Auth.badToken'), $result->reason());
169169

170170
// A login attempt should have always been recorded
171171
$this->seeInDatabase('auth_token_logins', [
@@ -178,7 +178,7 @@ public function testAttemptCannotFindUser()
178178
public function testAttemptSuccess()
179179
{
180180
/** @var User $user */
181-
$user = fake(UserModel::class);
181+
$user = \fake(UserModel::class);
182182
$token = $user->generateAccessToken('foo');
183183
$this->setRequestHeader($token->raw_token);
184184

@@ -205,7 +205,7 @@ public function testAttemptSuccess()
205205

206206
protected function setRequestHeader(string $token)
207207
{
208-
$request = service('request');
208+
$request = \service('request');
209209
$request->setHeader('Authorization', 'Bearer ' . $token);
210210
}
211211
}

tests/Authentication/SessionAuthenticatorTest.php renamed to tests/Authentication/Authenticators/SessionAuthenticatorTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\Authentication;
3+
namespace Tests\Authentication\Authenticators;
44

55
use CodeIgniter\Shield\Authentication\Authentication;
66
use CodeIgniter\Shield\Authentication\AuthenticationException;
@@ -34,7 +34,7 @@ protected function setUp(): void
3434

3535
$config = new Auth();
3636
$auth = new Authentication($config);
37-
$auth->setProvider(model(UserModel::class)); // @phpstan-ignore-line
37+
$auth->setProvider(\model(UserModel::class)); // @phpstan-ignore-line
3838

3939
/** @var Session $authenticator */
4040
$authenticator = $auth->factory('session');
@@ -70,7 +70,7 @@ public function testLoggedInWithRememberCookie()
7070

7171
// Insert remember-me token.
7272
/** @var RememberModel $rememberModel */
73-
$rememberModel = model(RememberModel::class);
73+
$rememberModel = \model(RememberModel::class);
7474
$selector = 'selector';
7575
$validator = 'validator';
7676
$expires = date('Y-m-d H:i:s', time() + setting('Auth.sessionConfig')['rememberLength']);
@@ -114,7 +114,7 @@ public function testLoginWithRemember()
114114
]);
115115

116116
// Cookie should have been set
117-
$response = service('response');
117+
$response = \service('response');
118118
$this->assertNotNull($response->getCookie('remember'));
119119
}
120120

@@ -134,7 +134,7 @@ public function testLogout()
134134
public function testLoginByIdBadUser()
135135
{
136136
$this->expectException(AuthenticationException::class);
137-
$this->expectExceptionMessage(lang('Auth.invalidUser'));
137+
$this->expectExceptionMessage(\lang('Auth.invalidUser'));
138138

139139
$this->auth->loginById(123);
140140
}
@@ -176,7 +176,7 @@ public function testForgetCurrentUser()
176176

177177
public function testForgetAnotherUser()
178178
{
179-
fake(RememberModel::class, ['user_id' => $this->user->id]);
179+
\fake(RememberModel::class, ['user_id' => $this->user->id]);
180180

181181
$this->seeInDatabase('auth_remember_tokens', ['user_id' => $this->user->id]);
182182

@@ -193,7 +193,7 @@ public function testCheckNoPassword()
193193

194194
$this->assertInstanceOf(Result::class, $result);
195195
$this->assertFalse($result->isOK());
196-
$this->assertSame(lang('Auth.badAttempt'), $result->reason());
196+
$this->assertSame(\lang('Auth.badAttempt'), $result->reason());
197197
}
198198

199199
public function testCheckCannotFindUser()
@@ -205,7 +205,7 @@ public function testCheckCannotFindUser()
205205

206206
$this->assertInstanceOf(Result::class, $result);
207207
$this->assertFalse($result->isOK());
208-
$this->assertSame(lang('Auth.badAttempt'), $result->reason());
208+
$this->assertSame(\lang('Auth.badAttempt'), $result->reason());
209209
}
210210

211211
public function testCheckBadPassword()
@@ -222,7 +222,7 @@ public function testCheckBadPassword()
222222

223223
$this->assertInstanceOf(Result::class, $result);
224224
$this->assertFalse($result->isOK());
225-
$this->assertSame(lang('Auth.invalidPassword'), $result->reason());
225+
$this->assertSame(\lang('Auth.invalidPassword'), $result->reason());
226226
}
227227

228228
public function testCheckSuccess()
@@ -253,7 +253,7 @@ public function testAttemptCannotFindUser()
253253

254254
$this->assertInstanceOf(Result::class, $result);
255255
$this->assertFalse($result->isOK());
256-
$this->assertSame(lang('Auth.badAttempt'), $result->reason());
256+
$this->assertSame(\lang('Auth.badAttempt'), $result->reason());
257257

258258
// A login attempt should have always been recorded
259259
$this->seeInDatabase('auth_logins', [
@@ -325,7 +325,7 @@ public function testAttemptCaseInsensitive()
325325
public function testAttemptUsernameOnly()
326326
{
327327
/** @var User $user */
328-
$user = fake(UserModel::class, ['username' => 'foorog']);
328+
$user = \fake(UserModel::class, ['username' => 'foorog']);
329329
$user->createEmailIdentity([
330330
'email' => 'FOO@example.com',
331331
'password' => 'secret123',

tests/Authentication/ChainFilterTest.php renamed to tests/Authentication/Filters/ChainFilterTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\Authentication;
3+
namespace Tests\Authentication\Filters;
44

55
use CodeIgniter\Config\Factories;
66
use CodeIgniter\Shield\Entities\AccessToken;
@@ -32,12 +32,12 @@ protected function setUp(): void
3232
$_SESSION = [];
3333

3434
// Register our filter
35-
$filterConfig = config('Filters');
35+
$filterConfig = \config('Filters');
3636
$filterConfig->aliases['chain'] = ChainAuth::class;
3737
Factories::injectMock('filters', 'filters', $filterConfig);
3838

3939
// Add a test route that we can visit to trigger.
40-
$routes = service('routes');
40+
$routes = \service('routes');
4141
$routes->group('/', ['filter' => 'chain'], static function ($routes) {
4242
$routes->get('protected-route', static function () {
4343
echo 'Protected';
@@ -71,8 +71,8 @@ public function testFilterSuccessSeession()
7171
$result->assertStatus(200);
7272
$result->assertSee('Protected');
7373

74-
$this->assertSame($this->user->id, auth()->id());
75-
$this->assertSame($this->user->id, auth()->user()->id);
74+
$this->assertSame($this->user->id, \auth()->id());
75+
$this->assertSame($this->user->id, \auth()->user()->id);
7676
}
7777

7878
public function testFilterSuccessTokens()
@@ -85,11 +85,11 @@ public function testFilterSuccessTokens()
8585
$result->assertStatus(200);
8686
$result->assertSee('Protected');
8787

88-
$this->assertSame($this->user->id, auth()->id());
89-
$this->assertSame($this->user->id, auth()->user()->id);
88+
$this->assertSame($this->user->id, \auth()->id());
89+
$this->assertSame($this->user->id, \auth()->user()->id);
9090

9191
// User should have the current token set.
92-
$this->assertInstanceOf(AccessToken::class, auth('tokens')->user()->currentAccessToken());
93-
$this->assertSame($token->id, auth('tokens')->user()->currentAccessToken()->id);
92+
$this->assertInstanceOf(AccessToken::class, \auth('tokens')->user()->currentAccessToken());
93+
$this->assertSame($token->id, \auth('tokens')->user()->currentAccessToken()->id);
9494
}
9595
}

tests/Authentication/SessionFilterTest.php renamed to tests/Authentication/Filters/SessionFilterTest.php

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

3-
namespace Tests\Authentication;
3+
namespace Tests\Authentication\Filters;
44

55
use CodeIgniter\Config\Factories;
66
use CodeIgniter\Shield\Filters\SessionAuth;
@@ -27,12 +27,12 @@ protected function setUp(): void
2727
$_SESSION = [];
2828

2929
// Register our filter
30-
$filterConfig = config('Filters');
30+
$filterConfig = \config('Filters');
3131
$filterConfig->aliases['sessionAuth'] = SessionAuth::class;
3232
Factories::injectMock('filters', 'filters', $filterConfig);
3333

3434
// Add a test route that we can visit to trigger.
35-
$routes = service('routes');
35+
$routes = \service('routes');
3636
$routes->group('/', ['filter' => 'sessionAuth'], static function ($routes) {
3737
$routes->get('protected-route', static function () {
3838
echo 'Protected';
@@ -58,7 +58,7 @@ public function testFilterNotAuthorized()
5858

5959
public function testFilterSuccess()
6060
{
61-
$user = fake(UserModel::class);
61+
$user = \fake(UserModel::class);
6262
$_SESSION['user']['id'] = $user->id;
6363

6464
$result = $this->withSession(['user' => ['id' => $user->id]])
@@ -67,9 +67,9 @@ public function testFilterSuccess()
6767
$result->assertStatus(200);
6868
$result->assertSee('Protected');
6969

70-
$this->assertSame($user->id, auth('session')->id());
71-
$this->assertSame($user->id, auth('session')->user()->id);
70+
$this->assertSame($user->id, \auth('session')->id());
71+
$this->assertSame($user->id, \auth('session')->user()->id);
7272
// Last Active should have been updated
73-
$this->assertNotEmpty(auth('session')->user()->last_active);
73+
$this->assertNotEmpty(\auth('session')->user()->last_active);
7474
}
7575
}

tests/Authentication/TokenFilterTest.php renamed to tests/Authentication/Filters/TokenFilterTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\Authentication;
3+
namespace Tests\Authentication\Filters;
44

55
use CodeIgniter\Config\Factories;
66
use CodeIgniter\Shield\Entities\AccessToken;
@@ -29,12 +29,12 @@ protected function setUp(): void
2929
$_SESSION = [];
3030

3131
// Register our filter
32-
$filterConfig = config('Filters');
32+
$filterConfig = \config('Filters');
3333
$filterConfig->aliases['tokenAuth'] = TokenAuth::class;
3434
Factories::injectMock('filters', 'filters', $filterConfig);
3535

3636
// Add a test route that we can visit to trigger.
37-
$routes = service('routes');
37+
$routes = \service('routes');
3838
$routes->group('/', ['filter' => 'tokenAuth'], static function ($routes) {
3939
$routes->get('protected-route', static function () {
4040
echo 'Protected';
@@ -61,7 +61,7 @@ public function testFilterNotAuthorized()
6161
public function testFilterSuccess()
6262
{
6363
/** @var User $user */
64-
$user = fake(UserModel::class);
64+
$user = \fake(UserModel::class);
6565
$token = $user->generateAccessToken('foo');
6666

6767
$result = $this->withHeaders(['Authorization' => 'Bearer ' . $token->raw_token])
@@ -70,11 +70,11 @@ public function testFilterSuccess()
7070
$result->assertStatus(200);
7171
$result->assertSee('Protected');
7272

73-
$this->assertSame($user->id, auth('tokens')->id());
74-
$this->assertSame($user->id, auth('tokens')->user()->id);
73+
$this->assertSame($user->id, \auth('tokens')->id());
74+
$this->assertSame($user->id, \auth('tokens')->user()->id);
7575

7676
// User should have the current token set.
77-
$this->assertInstanceOf(AccessToken::class, auth('tokens')->user()->currentAccessToken());
78-
$this->assertSame($token->id, auth('tokens')->user()->currentAccessToken()->id);
77+
$this->assertInstanceOf(AccessToken::class, \auth('tokens')->user()->currentAccessToken());
78+
$this->assertSame($token->id, \auth('tokens')->user()->currentAccessToken()->id);
7979
}
8080
}

0 commit comments

Comments
 (0)