/**
  * @test
  */
 public function it_can_refresh_a_user()
 {
     $updatedUser = $this->user;
     $updatedUser->city = 'Herent';
     $this->userService->expects($this->once())->method('getUserByUsername')->with($this->user->nick)->willReturn($updatedUser);
     $this->assertEquals($updatedUser, $this->userProvider->refreshUser($this->user));
 }
 /**
  * @inheritdoc
  */
 public function loadUserByUsername($username)
 {
     $user = $this->userService->getUserByUsername($username);
     if (is_null($user)) {
         throw new UsernameNotFoundException();
     }
     return $user;
 }
 /**
  * @return JsonResponse
  */
 public function getUser()
 {
     $user = null;
     $minimalUserInfo = $this->userSessionService->getMinimalUserInfo();
     if (is_null($minimalUserInfo)) {
         return new Response('No active user.', Response::HTTP_NOT_FOUND);
     }
     $user = $this->userService->getUser($minimalUserInfo->getId());
     return JsonResponse::create()->setData($user)->setPrivate();
 }
 /**
  * @inheritdoc
  */
 public function authenticate(TokenInterface $token)
 {
     $userId = $token->getUser();
     $user = $this->userService->getUser($userId);
     if (is_null($user)) {
         throw new AuthenticationException(sprintf('User with id %s does not exist.', $userId));
     }
     $token = new UiTIDToken($user->getRoles());
     $token->setUser($user);
     return $token;
 }
 /**
  * @test
  */
 public function it_throws_an_exception_when_a_user_does_not_exist()
 {
     $this->userService->expects($this->once())->method('getUser')->with('1')->willReturn(null);
     $this->setExpectedException(AuthenticationException::class);
     $this->authenticator->authenticate($this->unauthenticatedToken);
 }