Skip to content

Commit

Permalink
Add forgetUser() method to GuardHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
rtconner committed Dec 7, 2022
1 parent cad86c1 commit 73685ff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Auth/GuardHelpers.php
Expand Up @@ -95,6 +95,16 @@ public function setUser(AuthenticatableContract $user)
return $this;
}

/**
* Forget the user.
*
* @return void
*/
public function forgetUser()
{
$this->user = null;
}

/**
* Get the user provider used by the guard.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/Auth.php
Expand Up @@ -56,6 +56,7 @@
* @method static \Illuminate\Auth\SessionGuard setRequest(\Symfony\Component\HttpFoundation\Request $request)
* @method static \Illuminate\Support\Timebox getTimebox()
* @method static \Illuminate\Contracts\Auth\Authenticatable authenticate()
* @method static void forgetUser()
* @method static \Illuminate\Contracts\Auth\UserProvider getProvider()
* @method static void setProvider(\Illuminate\Contracts\Auth\UserProvider $provider)
* @method static void macro(string $name, object|callable $macro)
Expand Down
8 changes: 8 additions & 0 deletions tests/Auth/AuthGuardTest.php
Expand Up @@ -588,6 +588,14 @@ public function testLoginOnceFailure()
$this->assertFalse($guard->once(['foo']));
}

public function testForgetUserSetsUserToNull()
{
$user = m::mock(Authenticatable::class);
$guard = $this->getGuard()->setUser($user);
$guard->forgetUser();
$this->assertNull($guard->getUser());
}

protected function getGuard()
{
[$session, $provider, $request, $cookie, $timebox] = $this->getMocks();
Expand Down

0 comments on commit 73685ff

Please sign in to comment.