Completed
Pull Request — master (#169)
by Beñat
05:56
created

it_handles_reassigning_task()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 23

Duplication

Lines 30
Ratio 100 %

Importance

Changes 0
Metric Value
dl 30
loc 30
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 23
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Spec\Kreta\TaskManager\Application\Project\Task;
14
15
use Kreta\TaskManager\Application\Project\Task\ReassignTaskCommand;
16
use Kreta\TaskManager\Application\Project\Task\ReassignTaskHandler;
17
use Kreta\TaskManager\Domain\Model\Organization\MemberId;
18
use Kreta\TaskManager\Domain\Model\Organization\Organization;
19
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId;
20
use Kreta\TaskManager\Domain\Model\Organization\OrganizationRepository;
21
use Kreta\TaskManager\Domain\Model\Project\Project;
22
use Kreta\TaskManager\Domain\Model\Project\ProjectId;
23
use Kreta\TaskManager\Domain\Model\Project\ProjectRepository;
24
use Kreta\TaskManager\Domain\Model\Project\Task\Task;
25
use Kreta\TaskManager\Domain\Model\Project\Task\TaskDoesNotExistException;
26
use Kreta\TaskManager\Domain\Model\Project\Task\TaskId;
27
use Kreta\TaskManager\Domain\Model\Project\Task\TaskRepository;
28
use Kreta\TaskManager\Domain\Model\Project\Task\UnauthorizedTaskActionException;
29
use PhpSpec\ObjectBehavior;
30
use Prophecy\Argument;
31
32
class ReassignTaskHandlerSpec extends ObjectBehavior
33
{
34
    function let(
35
        OrganizationRepository $organizationRepository,
36
        ProjectRepository $projectRepository,
37
        TaskRepository $taskRepository
38
    ) {
39
        $this->beConstructedWith($organizationRepository, $projectRepository, $taskRepository);
40
    }
41
42
    function it_is_initializable()
43
    {
44
        $this->shouldHaveType(ReassignTaskHandler::class);
45
    }
46
47 View Code Duplication
    function it_handles_reassigning_task(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
        OrganizationRepository $organizationRepository,
49
        ProjectRepository $projectRepository,
50
        TaskRepository $taskRepository,
51
        ReassignTaskCommand $command,
52
        Task $task,
53
        ProjectId $projectId,
54
        Project $project,
55
        OrganizationId $organizationId,
56
        Organization $organization
57
    ) {
58
        $command->id()->shouldBeCalled()->willReturn('task-id');
59
        $command->assigneeId()->shouldBeCalled()->willReturn('new-assignee-id');
60
        $command->editorId()->shouldBeCalled()->willReturn('editor-id');
61
62
        $taskRepository->taskOfId(Argument::type(TaskId::class))->shouldBeCalled()->willReturn($task);
63
        $task->projectId()->shouldBeCalled()->willReturn($projectId);
64
65
        $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project);
66
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
67
68
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
69
        $organization->isMember(Argument::type(MemberId::class))->shouldBeCalled()->willReturn(true);
70
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
71
72
        $task->reassign(Argument::type(MemberId::class))->shouldBeCalled();
73
        $taskRepository->persist($task)->shouldBeCalled();
74
75
        $this->__invoke($command);
76
    }
77
78 View Code Duplication
    function it_does_not_allow_to_reassign_when_task_does_not_exist(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
        TaskRepository $taskRepository,
80
        ReassignTaskCommand $command
81
    ) {
82
        $command->id()->shouldBeCalled()->willReturn('task-id');
83
84
        $taskRepository->taskOfId(Argument::type(TaskId::class))->shouldBeCalled()->willReturn(null);
85
86
        $this->shouldThrow(TaskDoesNotExistException::class)->during('__invoke', [$command]);
87
    }
88
89
    function it_does_not_allow_to_reassign_when_editor_is_not_a_organization_member(
90
        OrganizationRepository $organizationRepository,
91
        ProjectRepository $projectRepository,
92
        TaskRepository $taskRepository,
93
        ReassignTaskCommand $command,
94
        Task $task,
95
        ProjectId $projectId,
96
        Project $project,
97
        OrganizationId $organizationId,
98
        Organization $organization
99
    ) {
100
        $command->id()->shouldBeCalled()->willReturn('task-id');
101
        $command->assigneeId()->shouldBeCalled()->willReturn('new-assignee-id');
102
        $command->editorId()->shouldBeCalled()->willReturn('editor-id');
103
104
        $taskRepository->taskOfId(Argument::type(TaskId::class))->shouldBeCalled()->willReturn($task);
105
        $task->projectId()->shouldBeCalled()->willReturn($projectId);
106
107
        $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project);
108
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
109
110
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
111
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
112
        $organization->isMember(Argument::type(MemberId::class))->shouldBeCalled()->willReturn(false);
113
114
        $this->shouldThrow(UnauthorizedTaskActionException::class)->during('__invoke', [$command]);
115
    }
116
}
117