Skip to content

Commit

Permalink
Merge pull request #8836 from HolgerW1/5.0
Browse files Browse the repository at this point in the history
[5.0] Guard method onceUsingId not returning false but throwing exception
  • Loading branch information
taylorotwell committed May 21, 2015
2 parents 7fb8c67 + d109800 commit fc7cc85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Illuminate/Auth/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,12 @@ public function loginUsingId($id, $remember = false)
*/
public function onceUsingId($id)
{
$this->setUser($this->provider->retrieveById($id));

return $this->user instanceof UserContract;
if ( ! is_null($user = $this->provider->retrieveById($id)))
{
$this->setUser($user);
return true;
}
return false;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Auth/AuthGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ public function testLoginUsingIdStoresInSessionAndLogsInWithUser()

$this->assertEquals($user, $guard->loginUsingId(10));
}


public function testOnceUsingIdFailure()
{
$guard = $this->getGuard();
$guard->getProvider()->shouldReceive('retrieveById')->once()->with(11)->andReturn(null);
$this->assertFalse($guard->onceUsingId(11));
}


public function testUserUsesRememberCookieIfItExists()
Expand Down

0 comments on commit fc7cc85

Please sign in to comment.