function it_does_not_allow_to_reassign_when_editor_is_not_a_organization_organizationMember(OrganizationRepository $organizationRepository, ProjectRepository $projectRepository, TaskRepository $taskRepository, ReassignTaskCommand $command, Task $task, ProjectId $projectId, Project $project, OrganizationId $organizationId, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('task-id');
     $command->assigneeId()->shouldBeCalled()->willReturn('new-assignee-id');
     $command->editorId()->shouldBeCalled()->willReturn('editor-id');
     $taskRepository->taskOfId(Argument::type(TaskId::class))->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);
     $organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedTaskActionException::class)->during__invoke($command);
 }
Exemple #2
0
 public function __invoke(ReassignTaskCommand $command)
 {
     $task = $this->taskRepository->taskOfId(TaskId::generate($command->id()));
     if (!$task instanceof Task) {
         throw new TaskDoesNotExistException();
     }
     $project = $this->projectRepository->projectOfId($task->projectId());
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     $newAssigneeId = UserId::generate($command->assigneeId());
     if (!$organization->isOrganizationMember(UserId::generate($command->editorId())) || !$organization->isOrganizationMember($newAssigneeId)) {
         throw new UnauthorizedTaskActionException();
     }
     $task->reassign($organization->organizationMember($newAssigneeId)->id());
     $this->taskRepository->persist($task);
 }