public function testItShould_handleSocialiteUser_userDoesNotExist()
 {
     $driver = uniqid();
     $socialiteUser = $this->createSocialiteUser();
     $result = $this->repository->handleSocialiteUser($socialiteUser, $driver);
     $this->assertInstanceOf(User::class, $result);
     $this->assertEquals($driver, $result->auth_driver);
     $this->assertEquals($socialiteUser->email, $result->email);
 }
 /**
  * @param string $authDriver
  * @param UserRepository $userRepository
  * @return RedirectResponse
  */
 public function handleProviderCallback(string $authDriver, UserRepository $userRepository) : RedirectResponse
 {
     /** @var User $socialiteUser */
     $socialiteUser = Socialite::driver($authDriver)->user();
     try {
         $user = $userRepository->handleSocialiteUser($socialiteUser, $authDriver);
     } catch (UserCreatedWithAnotherDriverException $e) {
         $message = sprintf("User with email '%s' exists, but was not created with %s.", $socialiteUser->email, $authDriver);
         if ($e->user->auth_driver) {
             $message .= sprintf(' Try to login with %s.', $e->user->auth_driver);
         } else {
             $message .= ' Try to login using email and password.';
         }
         return redirect('/login')->with('errors', new MessageBag([$message]));
     }
     Auth::login($user);
     return redirect('/home');
 }