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\Query\Project\Task; |
14
|
|
|
|
15
|
|
|
use Kreta\TaskManager\Application\DataTransformer\Project\Task\TaskDataTransformer; |
16
|
|
|
use Kreta\TaskManager\Application\Query\Project\Task\FilterTasksHandler; |
17
|
|
|
use Kreta\TaskManager\Application\Query\Project\Task\FilterTasksQuery; |
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\Organization\OrganizationSpecificationFactory; |
22
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Project; |
23
|
|
|
use Kreta\TaskManager\Domain\Model\Project\ProjectId; |
24
|
|
|
use Kreta\TaskManager\Domain\Model\Project\ProjectRepository; |
25
|
|
|
use Kreta\TaskManager\Domain\Model\Project\ProjectSpecificationFactory; |
26
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\Task; |
27
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskId; |
28
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskRepository; |
29
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskSpecificationFactory; |
30
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\UnauthorizedTaskResourceException; |
31
|
|
|
use Kreta\TaskManager\Domain\Model\User\UserId; |
32
|
|
|
use PhpSpec\ObjectBehavior; |
33
|
|
|
use Prophecy\Argument; |
34
|
|
|
|
35
|
|
|
class FilterTasksHandlerSpec extends ObjectBehavior |
36
|
|
|
{ |
37
|
|
|
function let( |
38
|
|
|
OrganizationRepository $organizationRepository, |
39
|
|
|
OrganizationSpecificationFactory $organizationSpecificationFactory, |
40
|
|
|
ProjectRepository $projectRepository, |
41
|
|
|
ProjectSpecificationFactory $projectSpecificationFactory, |
42
|
|
|
TaskRepository $repository, |
43
|
|
|
TaskSpecificationFactory $specificationFactory, |
44
|
|
|
TaskDataTransformer $dataTransformer |
45
|
|
|
) { |
46
|
|
|
$this->beConstructedWith( |
47
|
|
|
$organizationRepository, |
48
|
|
|
$organizationSpecificationFactory, |
49
|
|
|
$projectRepository, |
50
|
|
|
$projectSpecificationFactory, |
51
|
|
|
$repository, |
52
|
|
|
$specificationFactory, |
53
|
|
|
$dataTransformer |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
function it_is_initializable() |
58
|
|
|
{ |
59
|
|
|
$this->shouldHaveType(FilterTasksHandler::class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
function it_serializes_filtered_tasks( |
|
|
|
|
63
|
|
|
FilterTasksQuery $query, |
64
|
|
|
ProjectRepository $projectRepository, |
65
|
|
|
Project $project, |
66
|
|
|
Project $parentProject, |
67
|
|
|
ProjectId $projectId, |
68
|
|
|
OrganizationId $organizationId, |
69
|
|
|
OrganizationId $parentOrganizationId, |
70
|
|
|
OrganizationRepository $organizationRepository, |
71
|
|
|
Organization $organization, |
72
|
|
|
Organization $parentOrganization, |
73
|
|
|
TaskRepository $repository, |
74
|
|
|
Task $task, |
75
|
|
|
Task $parent, |
76
|
|
|
TaskId $parentId, |
77
|
|
|
TaskDataTransformer $dataTransformer |
78
|
|
|
) { |
79
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
80
|
|
|
$query->projectId()->shouldBeCalled()->willReturn('project-id'); |
81
|
|
|
$projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project); |
82
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
83
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
84
|
|
|
$organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
85
|
|
|
$query->title()->shouldBeCalled()->willReturn('task-title'); |
86
|
|
|
$query->parentId()->shouldBeCalled()->willReturn('parent-id'); |
87
|
|
|
|
88
|
|
|
$repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent); |
89
|
|
|
$parent->projectId()->shouldBeCalled()->willReturn($projectId); |
90
|
|
|
$projectRepository->projectOfId($projectId) |
91
|
|
|
->shouldBeCalled()->willReturn($parentProject); |
92
|
|
|
$parentProject->organizationId()->shouldBeCalled()->willReturn($parentOrganizationId); |
93
|
|
|
$organizationRepository->organizationOfId($parentOrganizationId) |
94
|
|
|
->shouldBeCalled()->willReturn($parentOrganization); |
95
|
|
|
$parentOrganization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
96
|
|
|
$parent->id()->shouldBeCalled()->willReturn($parentId); |
97
|
|
|
|
98
|
|
|
$query->priority()->shouldBeCalled()->willReturn('low'); |
99
|
|
|
$query->progress()->shouldBeCalled()->willReturn('doing'); |
100
|
|
|
$query->offset()->shouldBeCalled()->willReturn(0); |
101
|
|
|
$query->limit()->shouldBeCalled()->willReturn(-1); |
102
|
|
|
$repository->query(Argument::any())->shouldBeCalled()->willReturn([$task]); |
103
|
|
|
|
104
|
|
|
$dataTransformer->write($task)->shouldBeCalled(); |
105
|
|
|
$dataTransformer->read()->shouldBeCalled(); |
106
|
|
|
|
107
|
|
|
$this->__invoke($query)->shouldBeArray(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
View Code Duplication |
function it_does_not_serialize_filtered_tasks_when_the_user_does_not_allowed( |
|
|
|
|
111
|
|
|
FilterTasksQuery $query, |
112
|
|
|
ProjectRepository $projectRepository, |
113
|
|
|
Project $project, |
114
|
|
|
OrganizationId $organizationId, |
115
|
|
|
OrganizationRepository $organizationRepository, |
116
|
|
|
Organization $organization |
117
|
|
|
) { |
118
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
119
|
|
|
$query->projectId()->shouldBeCalled()->willReturn('project-id'); |
120
|
|
|
$projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project); |
121
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
122
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
123
|
|
|
$organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(false); |
124
|
|
|
|
125
|
|
|
$this->shouldThrow(UnauthorizedTaskResourceException::class)->during__invoke($query); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
View Code Duplication |
function it_does_not_serialize_filtered_tasks_when_the_user_does_not_allowed_to_access_parent_task( |
|
|
|
|
129
|
|
|
FilterTasksQuery $query, |
130
|
|
|
ProjectRepository $projectRepository, |
131
|
|
|
Project $project, |
132
|
|
|
Project $parentProject, |
133
|
|
|
ProjectId $projectId, |
134
|
|
|
OrganizationId $organizationId, |
135
|
|
|
OrganizationId $parentOrganizationId, |
136
|
|
|
OrganizationRepository $organizationRepository, |
137
|
|
|
Organization $organization, |
138
|
|
|
Organization $parentOrganization, |
139
|
|
|
TaskRepository $repository, |
140
|
|
|
Task $parent |
141
|
|
|
) { |
142
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
143
|
|
|
$query->projectId()->shouldBeCalled()->willReturn('project-id'); |
144
|
|
|
$projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project); |
145
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
146
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
147
|
|
|
$organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
148
|
|
|
$query->title()->shouldBeCalled()->willReturn('task-title'); |
149
|
|
|
$query->parentId()->shouldBeCalled()->willReturn('parent-id'); |
150
|
|
|
|
151
|
|
|
$repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent); |
152
|
|
|
$parent->projectId()->shouldBeCalled()->willReturn($projectId); |
153
|
|
|
$projectRepository->projectOfId($projectId) |
154
|
|
|
->shouldBeCalled()->willReturn($parentProject); |
155
|
|
|
$parentProject->organizationId()->shouldBeCalled()->willReturn($parentOrganizationId); |
156
|
|
|
$organizationRepository->organizationOfId($parentOrganizationId) |
157
|
|
|
->shouldBeCalled()->willReturn($parentOrganization); |
158
|
|
|
$parentOrganization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(false); |
159
|
|
|
|
160
|
|
|
$this->shouldThrow(UnauthorizedTaskResourceException::class)->during__invoke($query); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
function it_serializes_filtered_projects_without_parent_id( |
164
|
|
|
FilterTasksQuery $query, |
165
|
|
|
ProjectRepository $projectRepository, |
166
|
|
|
Project $project, |
167
|
|
|
OrganizationId $organizationId, |
168
|
|
|
OrganizationRepository $organizationRepository, |
169
|
|
|
Organization $organization, |
170
|
|
|
TaskRepository $repository, |
171
|
|
|
Task $task, |
172
|
|
|
TaskDataTransformer $dataTransformer |
173
|
|
|
) { |
174
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
175
|
|
|
$query->projectId()->shouldBeCalled()->willReturn('project-id'); |
176
|
|
|
$projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project); |
177
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
178
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
179
|
|
|
$organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
180
|
|
|
$query->title()->shouldBeCalled()->willReturn('task-title'); |
181
|
|
|
$query->parentId()->shouldBeCalled()->willReturn(null); |
182
|
|
|
|
183
|
|
|
$query->priority()->shouldBeCalled()->willReturn('low'); |
184
|
|
|
$query->progress()->shouldBeCalled()->willReturn('doing'); |
185
|
|
|
$query->offset()->shouldBeCalled()->willReturn(0); |
186
|
|
|
$query->limit()->shouldBeCalled()->willReturn(-1); |
187
|
|
|
$repository->query(Argument::any())->shouldBeCalled()->willReturn([$task]); |
188
|
|
|
|
189
|
|
|
$dataTransformer->write($task)->shouldBeCalled(); |
190
|
|
|
$dataTransformer->read()->shouldBeCalled(); |
191
|
|
|
|
192
|
|
|
$this->__invoke($query)->shouldBeArray(); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
function it_serializes_filtered_tasks_with_does_not_exist_task_parent( |
196
|
|
|
FilterTasksQuery $query, |
197
|
|
|
ProjectRepository $projectRepository, |
198
|
|
|
Project $project, |
199
|
|
|
OrganizationId $organizationId, |
200
|
|
|
OrganizationRepository $organizationRepository, |
201
|
|
|
Organization $organization, |
202
|
|
|
TaskRepository $repository, |
203
|
|
|
Task $task, |
204
|
|
|
TaskDataTransformer $dataTransformer |
205
|
|
|
) { |
206
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
207
|
|
|
$query->projectId()->shouldBeCalled()->willReturn('project-id'); |
208
|
|
|
$projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project); |
209
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
210
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
211
|
|
|
$organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
212
|
|
|
$query->title()->shouldBeCalled()->willReturn('task-title'); |
213
|
|
|
$query->parentId()->shouldBeCalled()->willReturn('parent-id'); |
214
|
|
|
|
215
|
|
|
$repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn(null); |
216
|
|
|
|
217
|
|
|
$query->priority()->shouldBeCalled()->willReturn('low'); |
218
|
|
|
$query->progress()->shouldBeCalled()->willReturn('doing'); |
219
|
|
|
$query->offset()->shouldBeCalled()->willReturn(0); |
220
|
|
|
$query->limit()->shouldBeCalled()->willReturn(-1); |
221
|
|
|
$repository->query(Argument::any())->shouldBeCalled()->willReturn([$task]); |
222
|
|
|
|
223
|
|
|
$dataTransformer->write($task)->shouldBeCalled(); |
224
|
|
|
$dataTransformer->read()->shouldBeCalled(); |
225
|
|
|
|
226
|
|
|
$this->__invoke($query)->shouldBeArray(); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
function it_serializes_filtered_projects_without_project_id( |
230
|
|
|
FilterTasksQuery $query, |
231
|
|
|
ProjectRepository $projectRepository, |
232
|
|
|
Project $project, |
233
|
|
|
Project $parentProject, |
234
|
|
|
ProjectId $projectId, |
235
|
|
|
ProjectId $parentProjectId, |
236
|
|
|
OrganizationId $organizationId, |
237
|
|
|
OrganizationId $parentOrganizationId, |
238
|
|
|
OrganizationRepository $organizationRepository, |
239
|
|
|
Organization $organization, |
240
|
|
|
Organization $parentOrganization, |
241
|
|
|
TaskRepository $repository, |
242
|
|
|
Task $task, |
243
|
|
|
Task $parent, |
244
|
|
|
TaskId $parentId, |
245
|
|
|
TaskDataTransformer $dataTransformer |
246
|
|
|
) { |
247
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
248
|
|
|
$query->projectId()->shouldBeCalled()->willReturn(null); |
249
|
|
|
$projectRepository->projectOfId(Argument::type(ProjectId::class))->shouldBeCalled()->willReturn(null); |
250
|
|
|
|
251
|
|
|
$organizationRepository->query(Argument::any())->shouldBeCalled()->willReturn([$organization]); |
252
|
|
|
$organization->id()->shouldBeCalled()->willReturn($organizationId); |
253
|
|
|
$projectRepository->query(Argument::any())->shouldBeCalled()->willReturn([$project]); |
254
|
|
|
$project->id()->shouldBeCalled()->willReturn($projectId); |
255
|
|
|
$query->title()->shouldBeCalled()->willReturn('task-title'); |
256
|
|
|
$query->parentId()->shouldBeCalled()->willReturn('parent-id'); |
257
|
|
|
|
258
|
|
|
$repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent); |
259
|
|
|
$parent->projectId()->shouldBeCalled()->willReturn($parentProjectId); |
260
|
|
|
$projectRepository->projectOfId($parentProjectId) |
261
|
|
|
->shouldBeCalled()->willReturn($parentProject); |
262
|
|
|
$parentProject->organizationId()->shouldBeCalled()->willReturn($parentOrganizationId); |
263
|
|
|
$organizationRepository->organizationOfId($parentOrganizationId) |
264
|
|
|
->shouldBeCalled()->willReturn($parentOrganization); |
265
|
|
|
$parentOrganization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
266
|
|
|
$parent->id()->shouldBeCalled()->willReturn($parentId); |
267
|
|
|
|
268
|
|
|
$query->priority()->shouldBeCalled()->willReturn('low'); |
269
|
|
|
$query->progress()->shouldBeCalled()->willReturn('doing'); |
270
|
|
|
$query->offset()->shouldBeCalled()->willReturn(0); |
271
|
|
|
$query->limit()->shouldBeCalled()->willReturn(-1); |
272
|
|
|
$repository->query(Argument::any())->shouldBeCalled()->willReturn([$task]); |
273
|
|
|
|
274
|
|
|
$dataTransformer->write($task)->shouldBeCalled(); |
275
|
|
|
$dataTransformer->read()->shouldBeCalled(); |
276
|
|
|
|
277
|
|
|
$this->__invoke($query)->shouldBeArray(); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
View Code Duplication |
function it_serializes_filtered_projects_without_title( |
|
|
|
|
281
|
|
|
FilterTasksQuery $query, |
282
|
|
|
ProjectRepository $projectRepository, |
283
|
|
|
Project $project, |
284
|
|
|
Project $parentProject, |
285
|
|
|
ProjectId $projectId, |
286
|
|
|
OrganizationId $organizationId, |
287
|
|
|
OrganizationId $parentOrganizationId, |
288
|
|
|
OrganizationRepository $organizationRepository, |
289
|
|
|
Organization $organization, |
290
|
|
|
Organization $parentOrganization, |
291
|
|
|
TaskRepository $repository, |
292
|
|
|
Task $task, |
293
|
|
|
Task $parent, |
294
|
|
|
TaskId $parentId, |
295
|
|
|
TaskDataTransformer $dataTransformer |
296
|
|
|
) { |
297
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
298
|
|
|
$query->projectId()->shouldBeCalled()->willReturn('project-id'); |
299
|
|
|
$projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project); |
300
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
301
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
302
|
|
|
$organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
303
|
|
|
$query->title()->shouldBeCalled(); |
304
|
|
|
$query->parentId()->shouldBeCalled()->willReturn('parent-id'); |
305
|
|
|
|
306
|
|
|
$repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent); |
307
|
|
|
$parent->projectId()->shouldBeCalled()->willReturn($projectId); |
308
|
|
|
$projectRepository->projectOfId($projectId) |
309
|
|
|
->shouldBeCalled()->willReturn($parentProject); |
310
|
|
|
$parentProject->organizationId()->shouldBeCalled()->willReturn($parentOrganizationId); |
311
|
|
|
$organizationRepository->organizationOfId($parentOrganizationId) |
312
|
|
|
->shouldBeCalled()->willReturn($parentOrganization); |
313
|
|
|
$parentOrganization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
314
|
|
|
$parent->id()->shouldBeCalled()->willReturn($parentId); |
315
|
|
|
|
316
|
|
|
$query->priority()->shouldBeCalled()->willReturn('low'); |
317
|
|
|
$query->progress()->shouldBeCalled()->willReturn('doing'); |
318
|
|
|
$query->offset()->shouldBeCalled()->willReturn(0); |
319
|
|
|
$query->limit()->shouldBeCalled()->willReturn(-1); |
320
|
|
|
$repository->query(Argument::any())->shouldBeCalled()->willReturn([$task]); |
321
|
|
|
|
322
|
|
|
$dataTransformer->write($task)->shouldBeCalled(); |
323
|
|
|
$dataTransformer->read()->shouldBeCalled(); |
324
|
|
|
|
325
|
|
|
$this->__invoke($query)->shouldBeArray(); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
View Code Duplication |
function it_serializes_filtered_projects_without_priority( |
|
|
|
|
329
|
|
|
FilterTasksQuery $query, |
330
|
|
|
ProjectRepository $projectRepository, |
331
|
|
|
Project $project, |
332
|
|
|
Project $parentProject, |
333
|
|
|
ProjectId $projectId, |
334
|
|
|
OrganizationId $organizationId, |
335
|
|
|
OrganizationId $parentOrganizationId, |
336
|
|
|
OrganizationRepository $organizationRepository, |
337
|
|
|
Organization $organization, |
338
|
|
|
Organization $parentOrganization, |
339
|
|
|
TaskRepository $repository, |
340
|
|
|
Task $task, |
341
|
|
|
Task $parent, |
342
|
|
|
TaskId $parentId, |
343
|
|
|
TaskDataTransformer $dataTransformer |
344
|
|
|
) { |
345
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
346
|
|
|
$query->projectId()->shouldBeCalled()->willReturn('project-id'); |
347
|
|
|
$projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project); |
348
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
349
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
350
|
|
|
$organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
351
|
|
|
$query->title()->shouldBeCalled()->willReturn('task-title'); |
352
|
|
|
$query->parentId()->shouldBeCalled()->willReturn('parent-id'); |
353
|
|
|
|
354
|
|
|
$repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent); |
355
|
|
|
$parent->projectId()->shouldBeCalled()->willReturn($projectId); |
356
|
|
|
$projectRepository->projectOfId($projectId) |
357
|
|
|
->shouldBeCalled()->willReturn($parentProject); |
358
|
|
|
$parentProject->organizationId()->shouldBeCalled()->willReturn($parentOrganizationId); |
359
|
|
|
$organizationRepository->organizationOfId($parentOrganizationId) |
360
|
|
|
->shouldBeCalled()->willReturn($parentOrganization); |
361
|
|
|
$parentOrganization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
362
|
|
|
$parent->id()->shouldBeCalled()->willReturn($parentId); |
363
|
|
|
|
364
|
|
|
$query->priority()->shouldBeCalled()->willReturn(null); |
365
|
|
|
$query->progress()->shouldBeCalled()->willReturn('doing'); |
366
|
|
|
$query->offset()->shouldBeCalled()->willReturn(0); |
367
|
|
|
$query->limit()->shouldBeCalled()->willReturn(-1); |
368
|
|
|
$repository->query(Argument::any())->shouldBeCalled()->willReturn([$task]); |
369
|
|
|
|
370
|
|
|
$dataTransformer->write($task)->shouldBeCalled(); |
371
|
|
|
$dataTransformer->read()->shouldBeCalled(); |
372
|
|
|
|
373
|
|
|
$this->__invoke($query)->shouldBeArray(); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
View Code Duplication |
function it_serializes_filtered_projects_without_progress( |
|
|
|
|
377
|
|
|
FilterTasksQuery $query, |
378
|
|
|
ProjectRepository $projectRepository, |
379
|
|
|
Project $project, |
380
|
|
|
Project $parentProject, |
381
|
|
|
ProjectId $projectId, |
382
|
|
|
OrganizationId $organizationId, |
383
|
|
|
OrganizationId $parentOrganizationId, |
384
|
|
|
OrganizationRepository $organizationRepository, |
385
|
|
|
Organization $organization, |
386
|
|
|
Organization $parentOrganization, |
387
|
|
|
TaskRepository $repository, |
388
|
|
|
Task $task, |
389
|
|
|
Task $parent, |
390
|
|
|
TaskId $parentId, |
391
|
|
|
TaskDataTransformer $dataTransformer |
392
|
|
|
) { |
393
|
|
|
$query->userId()->shouldBeCalled()->willReturn('user-id'); |
394
|
|
|
$query->projectId()->shouldBeCalled()->willReturn('project-id'); |
395
|
|
|
$projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project); |
396
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
397
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
398
|
|
|
$organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
399
|
|
|
$query->title()->shouldBeCalled()->willReturn('task-title'); |
400
|
|
|
$query->parentId()->shouldBeCalled()->willReturn('parent-id'); |
401
|
|
|
|
402
|
|
|
$repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent); |
403
|
|
|
$parent->projectId()->shouldBeCalled()->willReturn($projectId); |
404
|
|
|
$projectRepository->projectOfId($projectId) |
405
|
|
|
->shouldBeCalled()->willReturn($parentProject); |
406
|
|
|
$parentProject->organizationId()->shouldBeCalled()->willReturn($parentOrganizationId); |
407
|
|
|
$organizationRepository->organizationOfId($parentOrganizationId) |
408
|
|
|
->shouldBeCalled()->willReturn($parentOrganization); |
409
|
|
|
$parentOrganization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true); |
410
|
|
|
$parent->id()->shouldBeCalled()->willReturn($parentId); |
411
|
|
|
|
412
|
|
|
$query->priority()->shouldBeCalled()->willReturn('low'); |
413
|
|
|
$query->progress()->shouldBeCalled()->willReturn(null); |
414
|
|
|
$query->offset()->shouldBeCalled()->willReturn(0); |
415
|
|
|
$query->limit()->shouldBeCalled()->willReturn(-1); |
416
|
|
|
$repository->query(Argument::any())->shouldBeCalled()->willReturn([$task]); |
417
|
|
|
|
418
|
|
|
$dataTransformer->write($task)->shouldBeCalled(); |
419
|
|
|
$dataTransformer->read()->shouldBeCalled(); |
420
|
|
|
|
421
|
|
|
$this->__invoke($query)->shouldBeArray(); |
422
|
|
|
} |
423
|
|
|
} |
424
|
|
|
|
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.