예제 #1
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);
 }
예제 #2
0
 function it_grants_the_user_role(UserRepository $repository, User $user, GrantUserRoleCommand $command)
 {
     $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->grant($role)->shouldBeCalled();
     $repository->persist($user)->shouldBeCalled();
     $this->__invoke($command);
 }