Example #1
0
 /**
  * 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);
 }
 function it_revokes_the_user_role(RevokeUserRoleCommand $command, UserRepository $repository, User $user)
 {
     $command->id()->shouldBeCalled()->willReturn('user-id');
     $command->role()->shouldBeCalled()->willReturn('ROLE_USER');
     $id = new UserId('user-id');
     $role = new UserRole('ROLE_USER');
     $repository->userOfId($id)->shouldBeCalled()->willReturn($user);
     $user->revoke($role)->shouldBeCalled();
     $repository->persist($user)->shouldBeCalled();
     $this->__invoke($command);
 }