/** * 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); }
/** * Handles the given query. * * @param UserOfInvitationTokenQuery $aQuery The query * * @throws UserDoesNotExistException when the user does not exist * @throws UserTokenExpiredException when the token is expired * * @return mixed */ public function __invoke(UserOfInvitationTokenQuery $aQuery) { $user = $this->repository->userOfInvitationToken(new UserToken($aQuery->invitationToken())); if (null === $user) { throw new UserDoesNotExistException(); } if ($user->isInvitationTokenExpired()) { throw new UserTokenExpiredException(); } $this->dataTransformer->write($user); return $this->dataTransformer->read(); }
function it_does_not_get_the_user_because_the_invitation_token_is_expired(UserRepository $repository, UserOfInvitationTokenQuery $query, User $user) { $query->invitationToken()->shouldBeCalled()->willReturn('invitation-token'); $token = new UserToken('invitation-token'); $repository->userOfInvitationToken($token)->shouldBeCalled()->willReturn($user); $user->isInvitationTokenExpired()->shouldBeCalled()->willReturn(true); $this->shouldThrow(UserTokenExpiredException::class)->during__invoke($query); }
function it_does_not_sign_up_because_user_does_not_exist(ByInvitationSignUpUserCommand $command, UserRepository $repository) { $command->invitationToken()->shouldBeCalled()->willReturn('invitation-token'); $repository->userOfInvitationToken(new UserToken('invitation-token'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }