Skip to content

Commit cd7dbc2

Browse files
committed
Adapt tests
1 parent bb4cc8a commit cd7dbc2

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
1010
processIsolation="false"
11-
stopOnFailure="false">
11+
stopOnFailure="true">
1212
<testsuites>
1313
<testsuite name="Test Suite">
1414
<directory>tests</directory>

src/Services/AuthService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function logout()
315315
$user = Auth::user();
316316
if ($user instanceof Authenticatable) {
317317
if ($user instanceof Passportable) {
318-
$user->tokens->each->revoke();
318+
$user->tokens()->get()->each->revoke();
319319
event(new UserLogout($user));
320320
}
321321

tests/AuthServiceLoginTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Binaryk\LaravelRestify\Contracts\Passportable;
66
use Binaryk\LaravelRestify\Events\UserLoggedIn;
77
use Binaryk\LaravelRestify\Events\UserLogout;
8+
use Binaryk\LaravelRestify\Exceptions\AirlockUserException;
89
use Binaryk\LaravelRestify\Exceptions\AuthenticatableUserException;
910
use Binaryk\LaravelRestify\Exceptions\CredentialsDoesntMatch;
1011
use Binaryk\LaravelRestify\Exceptions\PassportUserException;
@@ -75,6 +76,7 @@ public function test_user_did_not_verified_email()
7576

7677
public function test_login_user_did_not_user_passport_trait_or_not_implement_pasportable()
7778
{
79+
$this->app['config']->set('restify.auth.provider', 'passport');
7880
$this->expectException(PassportUserException::class);
7981
$userMustVerify = (new class extends User implements MustVerifyEmail {
8082
use \Illuminate\Auth\MustVerifyEmail;
@@ -94,6 +96,28 @@ public function test_login_user_did_not_user_passport_trait_or_not_implement_pas
9496
$this->authService->login();
9597
}
9698

99+
public function test_login_user_did_not_user_passport_trait_or_not_implement_airlockable()
100+
{
101+
$this->app['config']->set('restify.auth.provider', 'airlock');
102+
$this->expectException(AirlockUserException::class);
103+
$userMustVerify = (new class extends User implements MustVerifyEmail {
104+
use \Illuminate\Auth\MustVerifyEmail;
105+
});
106+
107+
$userMustVerify->fill([
108+
'email' => '[email protected]',
109+
'email_verified_at' => Carbon::now(),
110+
]);
111+
112+
Auth::shouldReceive('attempt')
113+
->andReturnTrue();
114+
115+
Auth::shouldReceive('user')
116+
->andReturn($userMustVerify);
117+
118+
$this->authService->login();
119+
}
120+
97121
public function test_login_with_success()
98122
{
99123
Event::fake([
@@ -127,6 +151,8 @@ public function test_login_with_success()
127151
public function test_logout_success()
128152
{
129153
Event::fake();
154+
$this->app['config']->set('restify.auth.provider', 'passport');
155+
130156
$user = (new class extends \Binaryk\LaravelRestify\Tests\Fixtures\User {
131157
public function tokens()
132158
{

0 commit comments

Comments
 (0)