function it_does_not_change_password_because_the_token_is_expired(ByRequestRememberPasswordChangeUserPasswordCommand $command, UserRepository $repository, User $user)
 {
     $command->rememberPasswordToken()->shouldBeCalled()->willReturn('non-exist-remember-password-token');
     $repository->userOfRememberPasswordToken(new UserToken('non-exist-remember-password-token'))->shouldBeCalled()->willReturn($user);
     $user->isRememberPasswordTokenExpired()->shouldBeCalled()->willReturn(true);
     $this->shouldThrow(UserTokenExpiredException::class)->during__invoke($command);
 }
 /**
  * Handles the given command.
  *
  * @param ByRequestRememberPasswordChangeUserPasswordCommand $aCommand The command
  *
  * @throws UserTokenNotFoundException when the user does not exist
  * @throws UserTokenExpiredException  when the token is expired
  */
 public function __invoke(ByRequestRememberPasswordChangeUserPasswordCommand $aCommand)
 {
     $user = $this->repository->userOfRememberPasswordToken(new UserToken($aCommand->rememberPasswordToken()));
     if (null === $user) {
         throw new UserTokenNotFoundException();
     }
     if ($user->isRememberPasswordTokenExpired()) {
         throw new UserTokenExpiredException();
     }
     $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder));
     $this->repository->persist($user);
 }