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
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace Spec\Kreta\TaskManager\Domain\Model\Project\Task; |
16
|
|
|
|
17
|
|
|
use Kreta\SharedKernel\Domain\Model\AggregateRoot; |
18
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\MemberId; |
19
|
|
|
use Kreta\TaskManager\Domain\Model\Project\ProjectId; |
20
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\NumericId; |
21
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\Task; |
22
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskCreated; |
23
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskEdited; |
24
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskId; |
25
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskParentChanged; |
26
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskPriority; |
27
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskPriorityChanged; |
28
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskProgress; |
29
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskProgressChanged; |
30
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskReassigned; |
31
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskReporterChanged; |
32
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskTitle; |
33
|
|
|
use PhpSpec\ObjectBehavior; |
34
|
|
|
|
35
|
|
|
class TaskSpec extends ObjectBehavior |
36
|
|
|
{ |
37
|
|
View Code Duplication |
function let( |
|
|
|
|
38
|
|
|
TaskId $taskId, |
39
|
|
|
NumericId $numericId, |
40
|
|
|
TaskTitle $title, |
41
|
|
|
MemberId $reporter, |
42
|
|
|
MemberId $assignee, |
43
|
|
|
TaskPriority $priority, |
44
|
|
|
ProjectId $projectId |
45
|
|
|
) { |
46
|
|
|
$taskId->id()->willReturn('task-id'); |
47
|
|
|
$this->beConstructedWith( |
48
|
|
|
$taskId, |
49
|
|
|
$numericId, |
50
|
|
|
$title, |
51
|
|
|
'Description', |
52
|
|
|
$reporter, |
53
|
|
|
$assignee, |
54
|
|
|
$priority, |
55
|
|
|
$projectId |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_can_be_created( |
60
|
|
|
TaskId $taskId, |
61
|
|
|
NumericId $numericId, |
62
|
|
|
TaskTitle $title, |
63
|
|
|
MemberId $reporter, |
64
|
|
|
MemberId $assignee, |
65
|
|
|
TaskPriority $priority, |
66
|
|
|
ProjectId $projectId |
67
|
|
|
) { |
68
|
|
|
$this->shouldHaveType(Task::class); |
69
|
|
|
$this->shouldHaveType(AggregateRoot::class); |
70
|
|
|
|
71
|
|
|
$this->id()->shouldReturn($taskId); |
72
|
|
|
$this->numericId()->shouldReturn($numericId); |
73
|
|
|
$this->title()->shouldReturn($title); |
74
|
|
|
$this->description()->shouldReturn('Description'); |
75
|
|
|
$this->reporterId()->shouldReturn($reporter); |
76
|
|
|
$this->assigneeId()->shouldReturn($assignee); |
77
|
|
|
$this->priority()->shouldReturn($priority); |
78
|
|
|
$this->projectId()->shouldReturn($projectId); |
79
|
|
|
$this->parentId()->shouldReturn(null); |
80
|
|
|
$this->progress()->shouldReturnStatus(TaskProgress::TODO); |
81
|
|
|
$this->createdOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class); |
82
|
|
|
$this->updatedOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class); |
83
|
|
|
|
84
|
|
|
$this->shouldHavePublished(TaskCreated::class); |
85
|
|
|
|
86
|
|
|
$this->__toString()->shouldReturn('task-id'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function it_can_be_created_as_a_subtask( |
90
|
|
|
TaskId $taskId, |
91
|
|
|
NumericId $numericId, |
92
|
|
|
TaskTitle $title, |
93
|
|
|
MemberId $reporter, |
94
|
|
|
MemberId $assignee, |
95
|
|
|
TaskPriority $priority, |
96
|
|
|
ProjectId $projectId, |
97
|
|
|
TaskId $parentId |
98
|
|
|
) { |
99
|
|
|
$this->beConstructedWith( |
100
|
|
|
$taskId, |
101
|
|
|
$numericId, |
102
|
|
|
$title, |
103
|
|
|
'Description', |
104
|
|
|
$reporter, |
105
|
|
|
$assignee, |
106
|
|
|
$priority, |
107
|
|
|
$projectId, |
108
|
|
|
$parentId |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$this->shouldHaveType(Task::class); |
112
|
|
|
$this->shouldHaveType(AggregateRoot::class); |
113
|
|
|
|
114
|
|
|
$this->id()->shouldReturn($taskId); |
115
|
|
|
$this->numericId()->shouldReturn($numericId); |
116
|
|
|
$this->title()->shouldReturn($title); |
117
|
|
|
$this->description()->shouldReturn('Description'); |
118
|
|
|
$this->reporterId()->shouldReturn($reporter); |
119
|
|
|
$this->assigneeId()->shouldReturn($assignee); |
120
|
|
|
$this->priority()->shouldReturn($priority); |
121
|
|
|
$this->projectId()->shouldReturn($projectId); |
122
|
|
|
$this->parentId()->shouldReturn($parentId); |
123
|
|
|
$this->progress()->shouldReturnStatus(TaskProgress::TODO); |
124
|
|
|
$this->createdOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class); |
125
|
|
|
$this->updatedOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class); |
126
|
|
|
|
127
|
|
|
$this->shouldHavePublished(TaskCreated::class); |
128
|
|
|
|
129
|
|
|
$this->__toString()->shouldReturn('task-id'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
function it_can_be_edited(TaskTitle $title) |
133
|
|
|
{ |
134
|
|
|
$oldUpdatedOn = $this->updatedOn(); |
135
|
|
|
|
136
|
|
|
$this->edit($title, 'New description'); |
137
|
|
|
|
138
|
|
|
$this->title()->shouldReturn($title); |
139
|
|
|
$this->description()->shouldReturn('New description'); |
140
|
|
|
$this->updatedOn()->shouldNotEqual($oldUpdatedOn); |
141
|
|
|
|
142
|
|
|
$this->shouldHavePublished(TaskEdited::class); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
View Code Duplication |
function its_parent_can_be_changed(TaskId $parentId) |
|
|
|
|
146
|
|
|
{ |
147
|
|
|
$oldUpdatedOn = $this->updatedOn(); |
148
|
|
|
|
149
|
|
|
$this->changeParent($parentId); |
150
|
|
|
|
151
|
|
|
$this->parentId()->shouldReturn($parentId); |
152
|
|
|
$this->updatedOn()->shouldNotEqual($oldUpdatedOn); |
153
|
|
|
|
154
|
|
|
$this->shouldHavePublished(TaskParentChanged::class); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
View Code Duplication |
function its_parent_can_be_removed() |
|
|
|
|
158
|
|
|
{ |
159
|
|
|
$oldUpdatedOn = $this->updatedOn(); |
160
|
|
|
|
161
|
|
|
$this->changeParent(); |
162
|
|
|
|
163
|
|
|
$this->parentId()->shouldReturn(null); |
164
|
|
|
$this->updatedOn()->shouldNotEqual($oldUpdatedOn); |
165
|
|
|
|
166
|
|
|
$this->shouldHavePublished(TaskParentChanged::class); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
function its_progress_can_be_changed(TaskProgress $progress) |
170
|
|
|
{ |
171
|
|
|
$oldUpdatedOn = $this->updatedOn(); |
172
|
|
|
|
173
|
|
|
$this->changeProgress($progress); |
174
|
|
|
|
175
|
|
|
$this->progress()->shouldReturn($progress); |
176
|
|
|
$this->updatedOn()->shouldNotEqual($oldUpdatedOn); |
177
|
|
|
|
178
|
|
|
$this->shouldHavePublished(TaskProgressChanged::class); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
function it_can_be_reassigned(MemberId $assignee) |
182
|
|
|
{ |
183
|
|
|
$oldUpdatedOn = $this->updatedOn(); |
184
|
|
|
|
185
|
|
|
$this->reassign($assignee); |
186
|
|
|
|
187
|
|
|
$this->assigneeId()->shouldReturn($assignee); |
188
|
|
|
$this->updatedOn()->shouldNotEqual($oldUpdatedOn); |
189
|
|
|
|
190
|
|
|
$this->shouldHavePublished(TaskReassigned::class); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
function its_reporter_can_be_changed(MemberId $reporter) |
194
|
|
|
{ |
195
|
|
|
$oldUpdatedOn = $this->updatedOn(); |
196
|
|
|
|
197
|
|
|
$this->changeReporter($reporter); |
198
|
|
|
|
199
|
|
|
$this->reporterId()->shouldReturn($reporter); |
200
|
|
|
$this->updatedOn()->shouldNotEqual($oldUpdatedOn); |
201
|
|
|
|
202
|
|
|
$this->shouldHavePublished(TaskReporterChanged::class); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
function its_priority_can_be_changed(TaskPriority $priority) |
206
|
|
|
{ |
207
|
|
|
$oldUpdatedOn = $this->updatedOn(); |
208
|
|
|
|
209
|
|
|
$this->changePriority($priority); |
210
|
|
|
|
211
|
|
|
$this->priority()->shouldReturn($priority); |
212
|
|
|
$this->updatedOn()->shouldNotEqual($oldUpdatedOn); |
213
|
|
|
|
214
|
|
|
$this->shouldHavePublished(TaskPriorityChanged::class); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function getMatchers() |
218
|
|
|
{ |
219
|
|
|
return [ |
220
|
|
|
'returnStatus' => function (TaskProgress $subject, $key) { |
221
|
|
|
return $subject->progress() === $key; |
222
|
|
|
}, |
223
|
|
|
]; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
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.