Exemple #1
0
 function it_does_not_edit_a_task_because_task_edition_is_not_allowed(EditTaskCommand $command, TaskRepository $repository, Task $task, ProjectRepository $projectRepository, OrganizationRepository $organizationRepository, ProjectId $projectId, Project $project, OrganizationId $organizationId, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('task-id');
     $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn($task);
     $task->projectId()->shouldBeCalled()->willReturn($projectId);
     $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project);
     $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
     $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
     $command->editorId()->shouldBeCalled()->willReturn('editor-id');
     $organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedTaskActionException::class)->during__invoke($command);
 }
Exemple #2
0
 public function __invoke(EditTaskCommand $command)
 {
     $task = $this->repository->taskOfId(TaskId::generate($command->id()));
     if (!$task instanceof Task) {
         throw new TaskDoesNotExistException();
     }
     $project = $this->projectRepository->projectOfId($task->projectId());
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     if (!$organization->isOrganizationMember(UserId::generate($command->editorId()))) {
         throw new UnauthorizedTaskActionException();
     }
     $task->edit(new TaskTitle($command->title()), $command->description());
     $this->repository->persist($task);
 }