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); }
/** * Handles the given command. * * @param RevokeUserRoleCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(RevokeUserRoleCommand $aCommand) { $user = $this->repository->userOfId(new UserId($aCommand->id())); if (null === $user) { throw new UserDoesNotExistException(); } $user->revoke(new UserRole($aCommand->role())); $this->repository->persist($user); }