public function __invoke(AddOwnerToOrganizationCommand $command) { $organization = $this->repository->organizationOfId(OrganizationId::generate($command->organizationId())); if (!$organization instanceof Organization) { throw new OrganizationDoesNotExistException(); } if (!$organization->isOwner(UserId::generate($command->adderId()))) { throw new UnauthorizedOrganizationActionException(); } $organization->addOwner(UserId::generate($command->userId())); $this->repository->persist($organization); }
function it_adds_owner_to_organization(AddOwnerToOrganizationCommand $command, OrganizationRepository $repository, Organization $organization) { $organizationId = OrganizationId::generate('organization-id'); $command->organizationId()->shouldBeCalled()->willReturn('organization-id'); $repository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); $command->adderId()->shouldBeCalled()->willReturn('adder-id'); $organization->isOwner(UserId::generate('adder-id'))->shouldBeCalled()->willReturn(true); $command->userId()->shouldBeCalled()->willReturn('user-id'); $organization->addOwner(UserId::generate('user-id'))->shouldBeCalled(); $repository->persist(Argument::type(Organization::class))->shouldBeCalled(); $this->__invoke($command); }