function it_changes_password(ByRequestRememberPasswordChangeUserPasswordCommand $command, UserRepository $repository, User $user)
 {
     $command->rememberPasswordToken()->shouldBeCalled()->willReturn('remember-password-token');
     $repository->userOfRememberPasswordToken(new UserToken('remember-password-token'))->shouldBeCalled()->willReturn($user);
     $command->newPlainPassword()->shouldBeCalled()->willReturn('new-plain-pass');
     $user->isRememberPasswordTokenExpired()->shouldBeCalled()->willReturn(false);
     $user->changePassword(Argument::type(UserPassword::class))->shouldBeCalled();
     $repository->persist($user)->shouldBeCalled();
     $this->__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);
 }