function it_does_not_sign_up_if_user_email_already_exists(WithConfirmationSignUpUserCommand $command, UserRepository $repository, User $user)
 {
     $command->id()->shouldBeCalled()->willReturn('user-id');
     $id = new UserId('user-id');
     $repository->userOfId($id)->shouldBeCalled()->willReturn(null);
     $command->email()->shouldBeCalled()->willReturn('*****@*****.**');
     $email = new UserEmail('*****@*****.**');
     $repository->userOfEmail($email)->shouldBeCalled()->willReturn($user);
     $this->shouldThrow(UserAlreadyExistException::class)->during__invoke($command);
 }
 /**
  * Handles the given command.
  *
  * @param WithConfirmationSignUpUserCommand $aCommand The command
  *
  * @throws UserAlreadyExistException when the user id is already exists
  */
 public function __invoke(WithConfirmationSignUpUserCommand $aCommand)
 {
     $id = new UserId($aCommand->id());
     if (null !== $this->repository->userOfId($id)) {
         throw new UserAlreadyExistException();
     }
     $email = new UserEmail($aCommand->email());
     if (null !== $this->repository->userOfEmail($email)) {
         throw new UserAlreadyExistException();
     }
     $userRoles = array_map(function ($role) {
         return new UserRole($role);
     }, $aCommand->roles());
     $user = $this->factory->build($id, $email, UserPassword::fromPlain($aCommand->password(), $this->encoder), $userRoles);
     $this->repository->persist($user);
 }