Пример #1
0
 function it_does_not_allow_to_create_project_if_creator_is_not_organization_owner(OrganizationRepository $organizationRepository, ProjectRepository $projectRepository, CreateProjectCommand $command, Organization $organization)
 {
     $command->id()->willReturn('project-id');
     $command->organizationId()->willReturn('organization-id');
     $command->creatorId()->willReturn('creator-id');
     $projectRepository->projectOfId(Argument::type(ProjectId::class))->shouldBeCalled()->willReturn(null);
     $organizationRepository->organizationOfId(Argument::type(OrganizationId::class))->shouldBeCalled()->willReturn($organization);
     $organization->isOwner(UserId::generate('creator-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedCreateProjectException::class)->during('__invoke', [$command]);
 }
Пример #2
0
 public function __invoke(CreateProjectCommand $command)
 {
     $project = $this->projectRepository->projectOfId(ProjectId::generate($command->id()));
     if ($project instanceof Project) {
         throw new ProjectAlreadyExists($project->id());
     }
     $organizationId = OrganizationId::generate($command->organizationId());
     $organization = $this->organizationRepository->organizationOfId($organizationId);
     if (!$organization instanceof Organization) {
         throw new OrganizationDoesNotExistException();
     }
     if (!$organization->isOwner(UserId::generate($command->creatorId()))) {
         throw new UnauthorizedCreateProjectException();
     }
     $project = new Project(ProjectId::generate($command->id()), new ProjectName($command->name()), new Slug(null === $command->slug() ? $command->name() : $command->slug()), $organization->id());
     $this->projectRepository->persist($project);
 }