Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
 /**
  * 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);
 }
Esempio n. 3
0
 /**
  * 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);
 }
Esempio n. 4
0
 /**
  * Handles the given query.
  *
  * @param UserOfIdQuery $aQuery The query
  *
  * @throws UserDoesNotExistException when the user does not exist
  *
  * @return mixed
  */
 public function __invoke(UserOfIdQuery $aQuery)
 {
     $user = $this->repository->userOfId(new UserId($aQuery->id()));
     if (null === $user) {
         throw new UserDoesNotExistException();
     }
     $this->dataTransformer->write($user);
     return $this->dataTransformer->read();
 }
Esempio n. 5
0
 /**
  * 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);
 }
Esempio n. 6
0
 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);
 }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
 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);
 }
 /**
  * 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_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);
 }
 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);
 }
Esempio n. 12
0
 function it_does_not_logout_unknown_user(UserRepository $repository, LogOutUserCommand $command)
 {
     $command->id()->shouldBeCalled()->willReturn('user-id');
     $repository->userOfId(new UserId('user-id'))->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command);
 }