Completed
Pull Request — master (#143)
by Beñat
03:47 queued 46s
created

CreateTaskHandlerSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
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\CreateTaskCommand;
16
use Kreta\TaskManager\Application\Project\Task\CreateTaskHandler;
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\ProjectDoesNotExistException;
23
use Kreta\TaskManager\Domain\Model\Project\ProjectId;
24
use Kreta\TaskManager\Domain\Model\Project\ProjectRepository;
25
use Kreta\TaskManager\Domain\Model\Project\Task\Task;
26
use Kreta\TaskManager\Domain\Model\Project\Task\TaskAlreadyExistsException;
27
use Kreta\TaskManager\Domain\Model\Project\Task\TaskAndTaskParentCannotBeTheSameException;
28
use Kreta\TaskManager\Domain\Model\Project\Task\TaskCreationNotAllowedException;
29
use Kreta\TaskManager\Domain\Model\Project\Task\TaskId;
30
use Kreta\TaskManager\Domain\Model\Project\Task\TaskParentDoesNotExistException;
31
use Kreta\TaskManager\Domain\Model\Project\Task\TaskRepository;
32
use PhpSpec\ObjectBehavior;
33
use Prophecy\Argument;
34
35
class CreateTaskHandlerSpec extends ObjectBehavior
36
{
37
    function let(
38
        TaskRepository $repository,
39
        ProjectRepository $projectRepository,
40
        OrganizationRepository $organizationRepository
41
    ) {
42
        $this->beConstructedWith($repository, $projectRepository, $organizationRepository);
43
    }
44
45
    function it_is_initializable()
46
    {
47
        $this->shouldHaveType(CreateTaskHandler::class);
48
    }
49
50
    function it_creates_an_task(
51
        CreateTaskCommand $command,
52
        TaskRepository $repository,
53
        ProjectRepository $projectRepository,
54
        OrganizationRepository $organizationRepository,
55
        Project $project,
56
        OrganizationId $organizationId,
57
        Organization $organization,
58
        Task $parent,
59
        ProjectId $projectId
60
    ) {
61
        $command->projectId()->shouldBeCalled()->willReturn('project-id');
62
        $command->taskId()->shouldBeCalled()->willReturn('task-id');
63
        $command->parentId()->shouldBeCalled()->willReturn('parent-id');
64
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn(null);
65
        $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
66
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
67
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
68
        $command->creatorId()->shouldBeCalled()->willReturn('creator-id');
69
        $command->assigneeId()->shouldBeCalled()->willReturn('assignee-id');
70
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
71
        $organization->isMember(Argument::type(MemberId::class))->shouldBeCalled()->willReturn(true);
72
        $repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent);
73
        $command->title()->shouldBeCalled()->willReturn('Task title');
74
        $command->description()->shouldBeCalled()->willReturn('Task description');
75
        $command->priority()->shouldBeCalled()->willReturn('low');
76
        $project->id()->shouldBeCalled()->willReturn($projectId);
77
        $repository->persist(Argument::type(Task::class))->shouldBeCalled();
78
        $this->__invoke($command);
79
    }
80
81 View Code Duplication
    function it_creates_an_organization_without_task_id(
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...
82
        CreateTaskCommand $command,
83
        TaskRepository $repository,
84
        ProjectRepository $projectRepository,
85
        OrganizationRepository $organizationRepository,
86
        Project $project,
87
        OrganizationId $organizationId,
88
        Organization $organization,
89
        Task $parent,
90
        ProjectId $projectId
91
    ) {
92
        $command->projectId()->shouldBeCalled()->willReturn('project-id');
93
        $command->taskId()->shouldBeCalled()->willReturn(null);
94
        $command->parentId()->shouldBeCalled()->willReturn('parent-id');
95
        $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
96
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
97
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
98
        $command->creatorId()->shouldBeCalled()->willReturn('creator-id');
99
        $command->assigneeId()->shouldBeCalled()->willReturn('assignee-id');
100
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
101
        $organization->isMember(Argument::type(MemberId::class))->shouldBeCalled()->willReturn(true);
102
        $repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent);
103
        $command->title()->shouldBeCalled()->willReturn('Task title');
104
        $command->description()->shouldBeCalled()->willReturn('Task description');
105
        $command->priority()->shouldBeCalled()->willReturn('low');
106
        $project->id()->shouldBeCalled()->willReturn($projectId);
107
        $repository->persist(Argument::type(Task::class))->shouldBeCalled();
108
        $this->__invoke($command);
109
    }
110
111 View Code Duplication
    function it_creates_an_organization_without_parent_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...
112
        CreateTaskCommand $command,
113
        TaskRepository $repository,
114
        ProjectRepository $projectRepository,
115
        OrganizationRepository $organizationRepository,
116
        Project $project,
117
        OrganizationId $organizationId,
118
        Organization $organization,
119
        Task $parent,
0 ignored issues
show
Unused Code introduced by
The parameter $parent is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
120
        ProjectId $projectId
121
    ) {
122
        $command->projectId()->shouldBeCalled()->willReturn('project-id');
123
        $command->taskId()->shouldBeCalled()->willReturn('task-id');
124
        $command->parentId()->shouldBeCalled()->willReturn(null);
125
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn(null);
126
        $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
127
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
128
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
129
        $command->creatorId()->shouldBeCalled()->willReturn('creator-id');
130
        $command->assigneeId()->shouldBeCalled()->willReturn('assignee-id');
131
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
132
        $organization->isMember(Argument::type(MemberId::class))->shouldBeCalled()->willReturn(true);
133
        $command->title()->shouldBeCalled()->willReturn('Task title');
134
        $command->description()->shouldBeCalled()->willReturn('Task description');
135
        $command->priority()->shouldBeCalled()->willReturn('low');
136
        $project->id()->shouldBeCalled()->willReturn($projectId);
137
        $repository->persist(Argument::type(Task::class))->shouldBeCalled();
138
        $this->__invoke($command);
139
    }
140
    function it_does_not_create_a_task_because_task_and_parent_are_the_same(
141
        CreateTaskCommand $command
142
    ) {
143
        $command->taskId()->shouldBeCalled()->willReturn('task-id');
144
        $command->parentId()->shouldBeCalled()->willReturn('task-id');
145
        $this->shouldThrow(TaskAndTaskParentCannotBeTheSameException::class)->during__invoke($command);
146
    }
147
148
    function it_does_not_create_a_task_because_task_already_exists(
149
        CreateTaskCommand $command,
150
        TaskRepository $repository,
151
        Task $task
152
    ) {
153
        $command->taskId()->shouldBeCalled()->willReturn('task-id');
154
        $command->parentId()->shouldBeCalled()->willReturn(null);
155
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn($task);
156
        $this->shouldThrow(TaskAlreadyExistsException::class)->during__invoke($command);
157
    }
158
159
    function it_does_not_create_a_task_because_project_does_not_exist(
160
        CreateTaskCommand $command,
161
        TaskRepository $repository,
162
        ProjectRepository $projectRepository
163
    ) {
164
        $command->projectId()->shouldBeCalled()->willReturn('project-id');
165
        $command->taskId()->shouldBeCalled()->willReturn('task-id');
166
        $command->parentId()->shouldBeCalled()->willReturn(null);
167
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn(null);
168
        $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn(null);
169
        $this->shouldThrow(ProjectDoesNotExistException::class)->during__invoke($command);
170
    }
171
172
    function it_does_not_create_a_task_because_task_creation_is_not_allowed(
173
        CreateTaskCommand $command,
174
        TaskRepository $repository,
175
        ProjectRepository $projectRepository,
176
        OrganizationRepository $organizationRepository,
177
        Project $project,
178
        OrganizationId $organizationId,
179
        Organization $organization
180
    ) {
181
        $command->projectId()->shouldBeCalled()->willReturn('project-id');
182
        $command->taskId()->shouldBeCalled()->willReturn('task-id');
183
        $command->parentId()->shouldBeCalled()->willReturn('parent-id');
184
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn(null);
185
        $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
186
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
187
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
188
        $command->creatorId()->shouldBeCalled()->willReturn('creator-id');
189
        $command->assigneeId()->shouldBeCalled()->willReturn('assignee-id');
190
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
191
        $organization->isMember(Argument::type(MemberId::class))->shouldBeCalled()->willReturn(false);
192
        $this->shouldThrow(TaskCreationNotAllowedException::class)->during__invoke($command);
193
    }
194
195
    function it_does_not_create_a_task_because_parent_task_does_not_exist(
196
        CreateTaskCommand $command,
197
        TaskRepository $repository,
198
        ProjectRepository $projectRepository,
199
        OrganizationRepository $organizationRepository,
200
        Project $project,
201
        OrganizationId $organizationId,
202
        Organization $organization
203
    ) {
204
        $command->projectId()->shouldBeCalled()->willReturn('project-id');
205
        $command->taskId()->shouldBeCalled()->willReturn('task-id');
206
        $command->parentId()->shouldBeCalled()->willReturn('parent-id');
207
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn(null);
208
        $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
209
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
210
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
211
        $command->creatorId()->shouldBeCalled()->willReturn('creator-id');
212
        $command->assigneeId()->shouldBeCalled()->willReturn('assignee-id');
213
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
214
        $organization->isMember(Argument::type(MemberId::class))->shouldBeCalled()->willReturn(true);
215
        $repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn(null);
216
217
        $this->shouldThrow(TaskParentDoesNotExistException::class)->during__invoke($command);
218
    }
219
}
220