function it_creates_a_user_if_authorization_is_granted(Factory $socialite, UserRepository $users, Authenticator $auth, User $user, AuthenticateUserListener $listener)
 {
     $socialite->driver('github')->willReturn(new ProviderStub());
     $users->findByUsernameOrCreate(ProviderStub::$data)->willReturn($user);
     $auth->login($user, self::HAS_CODE)->shouldBeCalled();
     $listener->userHasLoggedIn($user)->shouldBeCalled();
     $this->execute(self::HAS_CODE, $listener);
 }
 /**
  * @param boolean $hasCode
  * @param AuthenticateUserListener $listener
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function execute($hasCode, AuthenticateUserListener $listener)
 {
     if (!$hasCode) {
         return $this->getAuthorizationFirst();
     }
     $user = $this->users->findByUsernameOrCreate($this->getGithubUser());
     $this->auth->login($user, true);
     return $listener->userHasLoggedIn($user);
 }