From c284bcbb56f11e4ce9a0d2397de37bb8fa18ea10 Mon Sep 17 00:00:00 2001 From: mpyw Date: Fri, 8 Jun 2018 23:44:12 +0900 Subject: [PATCH 1/3] Add GuardHelpers::alreadyAuthenticated() It behave similarly to `GuardHelpers::check()`, but it doesn't trigger any side effects. --- src/Illuminate/Auth/GuardHelpers.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Illuminate/Auth/GuardHelpers.php b/src/Illuminate/Auth/GuardHelpers.php index 9a682c3dce1c..2bb632ff71f3 100644 --- a/src/Illuminate/Auth/GuardHelpers.php +++ b/src/Illuminate/Auth/GuardHelpers.php @@ -40,6 +40,16 @@ public function authenticate() throw new AuthenticationException; } + /** + * Determine if the current user is already authenticated without triggering side effects. + * + * @return bool + */ + public function alreadyAuthenticated() + { + return ! is_null($this->user); + } + /** * Determine if the current user is authenticated. * From 58eca5b19ba25497f964a74e0c98ac9ad875a1c2 Mon Sep 17 00:00:00 2001 From: mpyw Date: Fri, 8 Jun 2018 23:57:59 +0900 Subject: [PATCH 2/3] Add test of Add GuardHelpers::alreadyAuthenticated() --- tests/Auth/AuthGuardTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Auth/AuthGuardTest.php b/tests/Auth/AuthGuardTest.php index 85bf17b30b36..ed09ed320aaf 100755 --- a/tests/Auth/AuthGuardTest.php +++ b/tests/Auth/AuthGuardTest.php @@ -178,6 +178,22 @@ public function testAuthenticateThrowsWhenUserIsNull() $guard->authenticate(); } + public function testAlreadyAuthenticatedReturnsFalseWhenUserIsNotNull() + { + $user = m::mock('Illuminate\Contracts\Auth\Authenticatable'); + $guard = $this->getGuard()->setUser($user); + + $this->assertTrue($guard->alreadyAuthenticated()); + } + + public function testAlreadyAuthenticatedReturnsFalseWhenUserIsNull() + { + $guard = $this->getGuard(); + $guard->getSession()->shouldNotReceive('get'); + + $this->assertFalse($guard->alreadyAuthenticated()); + } + public function testIsAuthedReturnsTrueWhenUserIsNotNull() { $user = m::mock('Illuminate\Contracts\Auth\Authenticatable'); From 6a9d9e3b953cb66499dd0ebe5cd0f0f2428320df Mon Sep 17 00:00:00 2001 From: mpyw Date: Sat, 9 Jun 2018 02:32:19 +0900 Subject: [PATCH 3/3] Rename GuardHelpers::alreadyAuthenticated() to GuardHelpers::hasUser() --- src/Illuminate/Auth/GuardHelpers.php | 4 ++-- tests/Auth/AuthGuardTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Auth/GuardHelpers.php b/src/Illuminate/Auth/GuardHelpers.php index 2bb632ff71f3..291c65d461af 100644 --- a/src/Illuminate/Auth/GuardHelpers.php +++ b/src/Illuminate/Auth/GuardHelpers.php @@ -41,11 +41,11 @@ public function authenticate() } /** - * Determine if the current user is already authenticated without triggering side effects. + * Determine if the guard has the current user without triggering side effects. * * @return bool */ - public function alreadyAuthenticated() + public function hasUser() { return ! is_null($this->user); } diff --git a/tests/Auth/AuthGuardTest.php b/tests/Auth/AuthGuardTest.php index ed09ed320aaf..f353da868dda 100755 --- a/tests/Auth/AuthGuardTest.php +++ b/tests/Auth/AuthGuardTest.php @@ -178,20 +178,20 @@ public function testAuthenticateThrowsWhenUserIsNull() $guard->authenticate(); } - public function testAlreadyAuthenticatedReturnsFalseWhenUserIsNotNull() + public function testHasUserReturnsFalseWhenUserIsNotNull() { $user = m::mock('Illuminate\Contracts\Auth\Authenticatable'); $guard = $this->getGuard()->setUser($user); - $this->assertTrue($guard->alreadyAuthenticated()); + $this->assertTrue($guard->hasUser()); } - public function testAlreadyAuthenticatedReturnsFalseWhenUserIsNull() + public function testHasUserReturnsFalseWhenUserIsNull() { $guard = $this->getGuard(); $guard->getSession()->shouldNotReceive('get'); - $this->assertFalse($guard->alreadyAuthenticated()); + $this->assertFalse($guard->hasUser()); } public function testIsAuthedReturnsTrueWhenUserIsNotNull()