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
  • Loading branch information
sileence committed Apr 26, 2016
1 parent 0a26661 commit 921a4d9
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 921a4d9

Please sign in to comment.