Ejemplo n.º 1
0
 public function __invoke(CreateTaskCommand $command)
 {
     if (null !== ($id = $command->taskId())) {
         $task = $this->repository->taskOfId(TaskId::generate($id));
         if ($command->parentId() === $command->taskId()) {
             throw new TaskAndTaskParentCannotBeTheSameException();
         }
         if ($task instanceof Task) {
             throw new TaskAlreadyExistsException();
         }
     }
     $project = $this->projectRepository->projectOfId(ProjectId::generate($command->projectId()));
     if (!$project instanceof Project) {
         throw new ProjectDoesNotExistException();
     }
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     $creatorId = UserId::generate($command->creatorId());
     $assigneeId = UserId::generate($command->assigneeId());
     if (!$organization->isOrganizationMember($creatorId) || !$organization->isOrganizationMember($assigneeId)) {
         throw new UnauthorizedTaskActionException();
     }
     if (null !== ($parentId = $command->parentId())) {
         $parent = $this->repository->taskOfId(TaskId::generate($parentId));
         if (!$parent instanceof Task) {
             throw new TaskParentDoesNotExistException();
         }
     }
     $task = new Task(TaskId::generate($id), new TaskTitle($command->title()), $command->description(), $organization->organizationMember($creatorId)->id(), $organization->organizationMember($assigneeId)->id(), new TaskPriority($command->priority()), $project->id(), TaskId::generate($parentId));
     $this->repository->persist($task);
 }
Ejemplo n.º 2
0
 function it_creates_an_organization_without_parent_task(CreateTaskCommand $command, TaskRepository $repository, ProjectRepository $projectRepository, OrganizationRepository $organizationRepository, Project $project, OrganizationId $organizationId, Organization $organization, ProjectId $projectId, Member $member, Member $member2, MemberId $memberId, MemberId $memberId2)
 {
     $command->projectId()->shouldBeCalled()->willReturn('project-id');
     $command->taskId()->shouldBeCalled()->willReturn('task-id');
     $command->parentId()->shouldBeCalled()->willReturn(null);
     $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn(null);
     $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
     $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
     $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
     $command->creatorId()->shouldBeCalled()->willReturn('creator-id');
     $command->assigneeId()->shouldBeCalled()->willReturn('assignee-id');
     $organization->isOrganizationMember(UserId::generate('creator-id'))->shouldBeCalled()->willReturn(true);
     $organization->isOrganizationMember(UserId::generate('assignee-id'))->shouldBeCalled()->willReturn(true);
     $organization->organizationMember(UserId::generate('creator-id'))->shouldBeCalled()->willReturn($member);
     $member->id()->shouldBeCalled()->willReturn($memberId);
     $organization->organizationMember(UserId::generate('assignee-id'))->shouldBeCalled()->willReturn($member2);
     $member2->id()->shouldBeCalled()->willReturn($memberId2);
     $command->title()->shouldBeCalled()->willReturn('Task title');
     $command->description()->shouldBeCalled()->willReturn('Task description');
     $command->priority()->shouldBeCalled()->willReturn('low');
     $project->id()->shouldBeCalled()->willReturn($projectId);
     $repository->persist(Argument::type(Task::class))->shouldBeCalled();
     $this->__invoke($command);
 }