Exemple #1
0
 function it_does_not_serialize_owner_because_it_does_not_exist(OwnerOfIdQuery $query, OrganizationRepository $repository, Organization $organization)
 {
     $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
     $repository->organizationOfId(OrganizationId::generate('organization-id'))->shouldBeCalled()->willReturn($organization);
     $query->userId()->shouldBeCalled()->willReturn('user-id');
     $organization->isOwner(UserId::generate('user-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(OwnerDoesNotExistException::class)->during__invoke($query);
 }
Exemple #2
0
 public function __invoke(OwnerOfIdQuery $query)
 {
     $organization = $this->repository->organizationOfId(OrganizationId::generate($query->organizationId()));
     if (!$organization instanceof Organization) {
         throw new OrganizationDoesNotExistException();
     }
     $userId = UserId::generate($query->userId());
     if (!$organization->isOwner($userId)) {
         throw new OwnerDoesNotExistException($userId);
     }
     $this->dataTransformer->write($organization->owner($userId));
     return $this->dataTransformer->read();
 }