function it_does_not_get_the_user_because_the_id_does_not_exist(UserRepository $repository, UserOfIdQuery $query) { $query->id()->shouldBeCalled()->willReturn('user-id'); $id = new UserId('user-id'); $repository->userOfId($id)->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($query); }
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); }
function it_removes_user(RemoveUserCommand $command, UserRepository $repository, User $user) { $command->id()->shouldBeCalled()->willReturn('user-id'); $repository->userOfId(new UserId('user-id'))->shouldBeCalled()->willReturn($user); $repository->remove($user)->shouldBeCalled(); $this->__invoke($command); }
function it_does_not_invite_when_the_user_does_not_exist(UserRepository $userRepository, ResendInvitationUserCommand $command) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $userRepository->userOfEmail($email)->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }
function it_does_not_revoke_the_user_role_because_the_user_does_not_exist(RevokeUserRoleCommand $command, UserRepository $repository) { $command->id()->shouldBeCalled()->willReturn('user-id'); $id = new UserId('user-id'); $repository->userOfId($id)->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }
function it_does_not_invite_when_user_already_exists(UserRepository $userRepository, User $user, InviteUserCommand $command) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $userRepository->userOfEmail($email)->shouldBeCalled()->willReturn($user); $this->shouldThrow(UserAlreadyExistException::class)->during__invoke($command); }
function it_does_not_get_the_user_because_the_email_does_not_exist(UserRepository $repository, UserOfEmailQuery $query) { $query->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $repository->userOfEmail($email)->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($query); }
/** * Handles the given command. * * @param RemoveUserCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(RemoveUserCommand $aCommand) { $user = $this->repository->userOfId(new UserId($aCommand->id())); if (null === $user) { throw new UserDoesNotExistException(); } $this->repository->remove($user); }
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_doesnt_activate_user_with_wrong_token(UserRepository $repository, User $user, EnableUserCommand $command) { $command->confirmationToken()->shouldBeCalled()->willReturn('confirmation-token'); $user->enableAccount()->shouldNotBeCalled(); $repository->userOfConfirmationToken(new UserToken('confirmation-token'))->shouldBeCalled()->willReturn(null); $repository->persist($user)->shouldNotBeCalled(); $this->shouldThrow(UserTokenNotFoundException::class)->during__invoke($command); }
function it_does_not_get_the_user_because_the_remember_password_token_is_expired(UserRepository $repository, UserOfRememberPasswordTokenQuery $query, User $user) { $query->rememberPasswordToken()->shouldBeCalled()->willReturn('remember-password-token'); $token = new UserToken('remember-password-token'); $repository->userOfRememberPasswordToken($token)->shouldBeCalled()->willReturn($user); $user->isRememberPasswordTokenExpired()->shouldBeCalled()->willReturn(true); $this->shouldThrow(UserTokenExpiredException::class)->during__invoke($query); }
/** * Handles the given command. * * @param RequestRememberPasswordCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(RequestRememberPasswordCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->rememberPassword(); $this->repository->persist($user); }
/** * Handles the given command. * * @param WithoutOldPasswordChangeUserPasswordCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(WithoutOldPasswordChangeUserPasswordCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder)); $this->repository->persist($user); }
/** * Handles the given command. * * @param ResendInvitationUserCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(ResendInvitationUserCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->regenerateInvitationToken(); $this->repository->persist($user); }
/** * Handles the given command. * * @param GrantUserRoleCommand $aCommand The command * * @throws UserDoesNotExistException when user does not exist */ public function __invoke(GrantUserRoleCommand $aCommand) { $user = $this->repository->userOfId(new UserId($aCommand->id())); if (null === $user) { throw new UserDoesNotExistException(); } $user->grant(new UserRole($aCommand->role())); $this->repository->persist($user); }
/** * Handles the given command. * * @param LogOutUserCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(LogOutUserCommand $aCommand) { $user = $this->repository->userOfId(new UserId($aCommand->id())); if (null === $user) { throw new UserDoesNotExistException(); } $user->logout(); $this->repository->persist($user); }
/** * Handles the given query. * * @param UserOfEmailQuery $aQuery The query * * @throws UserDoesNotExistException when the user does not exist * * @return mixed */ public function __invoke(UserOfEmailQuery $aQuery) { $user = $this->repository->userOfEmail(new UserEmail($aQuery->email())); if (null === $user) { throw new UserDoesNotExistException(); } $this->dataTransformer->write($user); return $this->dataTransformer->read(); }
/** * Handles the given command. * * @param LogInUserCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(LogInUserCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->login($aCommand->password(), $this->encoder); $this->repository->persist($user); }
/** * Handles the given command. * * @param EnableUserCommand $aCommand The command * * @throws UserTokenNotFoundException when the user token does not exist */ public function __invoke(EnableUserCommand $aCommand) { $confirmationToken = $aCommand->confirmationToken(); $user = $this->repository->userOfConfirmationToken(new UserToken($confirmationToken)); if (null === $user) { throw new UserTokenNotFoundException(); } $user->enableAccount(); $this->repository->persist($user); }
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 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 command. * * @param ChangeUserPasswordCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist * @throws UserPasswordInvalidException when the user password is invalid */ public function __invoke(ChangeUserPasswordCommand $aCommand) { $user = $this->repository->userOfId(new UserId($aCommand->id())); if (null === $user) { throw new UserDoesNotExistException(); } if (false === $user->password()->equals($aCommand->oldPlainPassword(), $this->encoder)) { throw new UserPasswordInvalidException(); } $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder)); $this->repository->persist($user); }
/** * 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); }
/** * 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(); }
/** * Handles the given command. * * @param InviteUserCommand $aCommand The command * * @throws UserAlreadyExistException when the user already exists */ public function __invoke(InviteUserCommand $aCommand) { $email = new UserEmail($aCommand->email()); $user = $this->repository->userOfEmail($email); if (null !== $user) { throw new UserAlreadyExistException(); } $user = $this->factory->build(new UserId($aCommand->id()), $email, array_map(function ($role) { return new UserRole($role); }, $aCommand->roles())); $this->repository->persist($user); }
/** * 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); }
function it_does_not_change_password_because_user_does_not_exist(ChangeUserPasswordCommand $command, UserRepository $repository) { $command->id()->shouldBeCalled()->willReturn('non-exist-user-id'); $repository->userOfId(new UserId('non-exist-user-id'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }
function it_does_not_request_remember_password_because_user_does_not_exist(RequestRememberPasswordCommand $command, UserRepository $repository) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }
function it_does_not_changes_password_because_the_does_not_exist(WithoutOldPasswordChangeUserPasswordCommand $command, UserRepository $repository) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }
function it_does_not_log_if_user_does_not_exist(UserRepository $repository, LogInUserCommand $command) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }