function it_signs_the_user_up(ByInvitationSignUpUserCommand $command, UserRepository $repository, User $user)
 {
     $command->invitationToken()->shouldBeCalled()->willReturn('invitation-token');
     $repository->userOfInvitationToken(new UserToken('invitation-token'))->shouldBeCalled()->willReturn($user);
     $command->password()->shouldBeCalled()->willReturn('plain-password');
     $user->changePassword(Argument::type(UserPassword::class))->shouldBeCalled();
     $user->acceptInvitation()->shouldBeCalled();
     $repository->persist($user)->shouldBeCalled();
     $this->__invoke($command);
 }
 /**
  * Handles the given command.
  *
  * @param ByInvitationSignUpUserCommand $aCommand The command
  *
  * @throws UserDoesNotExistException when the user does not exist
  */
 public function __invoke(ByInvitationSignUpUserCommand $aCommand)
 {
     $user = $this->userRepository->userOfInvitationToken(new UserToken($aCommand->invitationToken()));
     if (null === $user) {
         throw new UserDoesNotExistException();
     }
     $user->changePassword(UserPassword::fromPlain($aCommand->password(), $this->encoder));
     $user->acceptInvitation();
     $this->userRepository->persist($user);
 }