示例#1
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);
 }
 function it_edits_an_organization_without_slug(EditOrganizationCommand $command, OrganizationRepository $repository, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('organization-id');
     $repository->organizationOfId(OrganizationId::generate('organization-id'))->shouldBeCalled()->willReturn($organization);
     $command->name()->shouldBeCalled()->willReturn('Organization name');
     $command->slug()->shouldBeCalled()->willReturn(null);
     $command->userId()->shouldBeCalled()->willReturn('editor-id');
     $organization->isOwner(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(true);
     $organization->edit(new OrganizationName('Organization name'), new Slug('Organization name'))->shouldBeCalled();
     $repository->persist(Argument::type(Organization::class))->shouldBeCalled();
     $this->__invoke($command);
 }