function it_does_not_serialize_organization_member_because_it_does_not_exist(OrganizationMemberOfIdQuery $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->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(false); $this->shouldThrow(OrganizationMemberDoesNotExistException::class)->during__invoke($query); }
public function __invoke(OrganizationMemberOfIdQuery $query) { $organization = $this->repository->organizationOfId(OrganizationId::generate($query->organizationId())); if (!$organization instanceof Organization) { throw new OrganizationDoesNotExistException(); } $userId = UserId::generate($query->userId()); if (!$organization->isOrganizationMember($userId)) { throw new OrganizationMemberDoesNotExistException($userId); } $this->dataTransformer->write($organization->organizationMember($userId)); return $this->dataTransformer->read(); }