Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add forgetUser() method to GuardHelpers #45208

Merged
merged 1 commit into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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