Skip to content

Commit

Permalink
Fix seeAuthenticatedAs when using 2 different user models that repres…
Browse files Browse the repository at this point in the history
…ent the same user (#13308)
  • Loading branch information
sileence authored and taylorotwell committed Apr 27, 2016
1 parent 733ceda commit b6735f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ protected function isAuthenticated($guard = null)
*/
public function seeIsAuthenticatedAs($user, $guard = null)
{
$expected = $this->app->make('auth')->guard($guard)->user();

$this->assertInstanceOf(
get_class($expected), $user,
'The logged in user is not the same'
);

$this->assertSame(
$this->app->make('auth')->guard($guard)->user(), $user,
$expected->getAuthIdentifier(), $user->getAuthIdentifier(),
'The logged in user is not the same'
);

Expand Down
12 changes: 10 additions & 2 deletions tests/Foundation/FoundationAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,20 @@ public function testDontSeeIsAuthenticated()

public function testSeeIsAuthenticatedAs()
{
$expected = m::mock(Authenticatable::class);
$expected->shouldReceive('getAuthIdentifier')
->andReturn('1');

$this->mockGuard()
->shouldReceive('user')
->once()
->andReturn('Someone');
->andReturn($expected);

$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')
->andReturn('1');

$this->seeIsAuthenticatedAs('Someone');
$this->seeIsAuthenticatedAs($user);
}

protected function setupProvider(array $credentials)
Expand Down

0 comments on commit b6735f7

Please sign in to comment.