function it_does_not_edits_an_organization_because_the_owner_does_not_authorized(EditOrganizationCommand $command, OrganizationRepository $repository, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('organization-id');
     $repository->organizationOfId(OrganizationId::generate('organization-id'))->shouldBeCalled()->willReturn($organization);
     $command->userId()->shouldBeCalled()->willReturn('editor-id');
     $organization->isOwner(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedEditOrganizationException::class)->during__invoke($command);
 }
Example #2
0
 public function __invoke(EditOrganizationCommand $command)
 {
     $organization = $this->repository->organizationOfId(OrganizationId::generate($command->id()));
     if (!$organization instanceof Organization) {
         throw new OrganizationDoesNotExistException();
     }
     if (!$organization->isOwner(UserId::generate($command->userId()))) {
         throw new UnauthorizedEditOrganizationException();
     }
     $organization->edit(new OrganizationName($command->name()), new Slug(null === $command->slug() ? $command->name() : $command->slug()));
     $this->repository->persist($organization);
 }