public function test_login_uses_existing_user_if_matching_user_exists() { $auth = M::mock('Illuminate\\Auth\\AuthManager'); $users = M::mock('AdamWathan\\EloquentOAuth\\UserStore')->shouldIgnoreMissing(); $identities = M::mock('AdamWathan\\EloquentOAuth\\IdentityStore')->shouldIgnoreMissing(); $userDetails = M::mock('AdamWathan\\EloquentOAuth\\ProviderUserDetails'); $identity = new OAuthIdentity(); $user = M::mock('stdClass')->shouldIgnoreMissing(); $authenticator = new Authenticator($auth, $users, $identities); $identities->shouldReceive('userExists')->andReturn(true); $identities->shouldReceive('getByProvider')->andReturn($identity); $users->shouldReceive('create')->never(); $users->shouldReceive('findByIdentity')->andReturn($user); $auth->shouldReceive('login')->with($user)->once(); $authenticator->login('provider', $userDetails); }
public function test_if_nothing_is_returned_from_the_callback_the_found_or_created_user_is_used() { $providerAlias = 'provider'; $userDetails = new SocialNormUser([]); $foundUser = M::mock('Illuminate\\Contracts\\Auth\\Authenticatable')->shouldIgnoreMissing(); $otherUser = M::mock('Illuminate\\Contracts\\Auth\\Authenticatable')->shouldIgnoreMissing(); $auth = M::spy(); $users = M::spy(['findByIdentity' => $foundUser]); $identities = M::spy(['userExists' => true, 'getByProvider' => new OAuthIdentity()]); $authenticator = new Authenticator($auth, $users, $identities); $authenticator->login('provider', $userDetails, function () { return; }); $users->shouldNotHaveReceived('create'); $users->shouldHaveReceived('store')->with($foundUser); $identities->shouldHaveReceived('store'); $auth->shouldHaveReceived('login')->with($foundUser); }
public function test_login_uses_existing_user_if_matching_user_exists() { $providerAlias = 'provider'; $auth = M::spy(); $users = M::spy(); $identities = M::spy(); $userDetails = new SocialNormUser([]); $user = M::mock('Illuminate\\Contracts\\Auth\\Authenticatable')->shouldIgnoreMissing(); $identities->shouldReceive('userExists')->andReturn(true); $identities->shouldReceive('getByProvider')->andReturn(new OAuthIdentity()); $users->shouldReceive('findByIdentity')->andReturn($user); $authenticator = new Authenticator($auth, $users, $identities); $authenticator->login('provider', $userDetails); $users->shouldNotHaveReceived('create'); $users->shouldHaveReceived('store')->with($user); $identities->shouldHaveReceived('store'); $auth->shouldHaveReceived('login')->with($user); }