/**
  * @param string $identity
  * @param array $attributes
  * @param array $roles
  * @param mixed $user
  *
  * @return \Fp\OpenIdBundle\Security\Core\Authentication\Token\OpenIdToken
  */
 protected function createAuthenticatedToken($identity, array $attributes, array $roles, $user)
 {
     if ($user instanceof UserInterface) {
         $this->userChecker->checkPostAuth($user);
     }
     $newToken = new OpenIdToken($this->providerKey, $identity, $roles);
     $newToken->setUser($user);
     $newToken->setAttributes($attributes);
     $newToken->setAuthenticated(true);
     return $newToken;
 }
 /**
  * @test
  */
 public function shouldWrapAnyThrownExceptionsAsAuthenticatedServiceException()
 {
     $providerKey = 'main';
     $expectedPreviousException = new \Exception($expectedMessage = 'Something goes wrong', $expectedCode = 23);
     $userProviderMock = $this->createUserProviderMock();
     $userProviderMock->expects($this->once())->method('loadUserByUsername')->will($this->throwException($expectedPreviousException));
     $authProvider = new OpenIdAuthenticationProvider($providerKey, $userProviderMock, $this->createUserCheckerMock());
     $token = new OpenIdToken($providerKey, 'identity');
     $token->setUser('');
     try {
         $authProvider->authenticate($token);
     } catch (AuthenticationServiceException $e) {
         $this->assertSame($expectedPreviousException, $e->getPrevious());
         $this->assertEquals($expectedMessage, $e->getMessage());
         $this->assertEquals($expectedCode, $e->getCode());
         $this->assertNull($e->getToken());
         return;
     }
     $this->fail('Expected exception: AuthenticationServiceException was not thrown');
 }