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

TaskSpec::its_priority_can_be_changed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
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\Domain\Model\Project\Task;
14
15
use Kreta\SharedKernel\Domain\Model\AggregateRoot;
16
use Kreta\TaskManager\Domain\Model\Organization\MemberId;
17
use Kreta\TaskManager\Domain\Model\Project\ProjectId;
18
use Kreta\TaskManager\Domain\Model\Project\Task\Task;
19
use Kreta\TaskManager\Domain\Model\Project\Task\TaskCreated;
20
use Kreta\TaskManager\Domain\Model\Project\Task\TaskEdited;
21
use Kreta\TaskManager\Domain\Model\Project\Task\TaskId;
22
use Kreta\TaskManager\Domain\Model\Project\Task\TaskPriority;
23
use Kreta\TaskManager\Domain\Model\Project\Task\TaskPriorityChanged;
24
use Kreta\TaskManager\Domain\Model\Project\Task\TaskProgress;
25
use Kreta\TaskManager\Domain\Model\Project\Task\TaskProgressChanged;
26
use Kreta\TaskManager\Domain\Model\Project\Task\TaskReassigned;
27
use Kreta\TaskManager\Domain\Model\Project\Task\TaskTitle;
28
use PhpSpec\ObjectBehavior;
29
30
class TaskSpec extends ObjectBehavior
31
{
32 View Code Duplication
    function let(
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...
33
        TaskId $taskId,
34
        TaskTitle $title,
35
        MemberId $creator,
36
        MemberId $assignee,
37
        TaskPriority $priority,
38
        ProjectId $projectId
39
    ) {
40
        $taskId->id()->willReturn('task-id');
41
        $this->beConstructedWith($taskId, $title, 'Description', $creator, $assignee, $priority, $projectId);
42
    }
43
44
    function it_can_be_created(
45
        TaskId $taskId,
46
        TaskTitle $title,
47
        MemberId $creator,
48
        MemberId $assignee,
49
        TaskPriority $priority,
50
        ProjectId $projectId
51
    ) {
52
        $this->shouldHaveType(Task::class);
53
        $this->shouldHaveType(AggregateRoot::class);
54
55
        $this->id()->shouldReturn($taskId);
56
        $this->title()->shouldReturn($title);
57
        $this->description()->shouldReturn('Description');
58
        $this->creatorId()->shouldReturn($creator);
59
        $this->assigneeId()->shouldReturn($assignee);
60
        $this->priority()->shouldReturn($priority);
61
        $this->projectId()->shouldReturn($projectId);
62
        $this->parentId()->shouldReturn(null);
63
        $this->progress()->shouldReturnStatus(TaskProgress::TODO);
64
        $this->createdOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
65
        $this->updatedOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
66
67
        $this->shouldHavePublished(TaskCreated::class);
68
69
        $this->__toString()->shouldReturn('task-id');
70
    }
71
72
    function it_can_be_created_as_a_subtask(
73
        TaskId $taskId,
74
        TaskTitle $title,
75
        MemberId $creator,
76
        MemberId $assignee,
77
        TaskPriority $priority,
78
        ProjectId $projectId,
79
        TaskId $parentId
80
    ) {
81
        $this->beConstructedWith($taskId, $title, 'Description', $creator, $assignee, $priority, $projectId, $parentId);
82
83
        $this->shouldHaveType(Task::class);
84
        $this->shouldHaveType(AggregateRoot::class);
85
86
        $this->id()->shouldReturn($taskId);
87
        $this->title()->shouldReturn($title);
88
        $this->description()->shouldReturn('Description');
89
        $this->creatorId()->shouldReturn($creator);
90
        $this->assigneeId()->shouldReturn($assignee);
91
        $this->priority()->shouldReturn($priority);
92
        $this->projectId()->shouldReturn($projectId);
93
        $this->parentId()->shouldReturn($parentId);
94
        $this->progress()->shouldReturnStatus(TaskProgress::TODO);
95
        $this->createdOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
96
        $this->updatedOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
97
98
        $this->shouldHavePublished(TaskCreated::class);
99
100
        $this->__toString()->shouldReturn('task-id');
101
    }
102
103
    function it_can_be_edited(TaskTitle $title)
104
    {
105
        $oldUpdatedOn = $this->updatedOn();
106
107
        $this->edit($title, 'New description');
108
109
        $this->title()->shouldReturn($title);
110
        $this->description()->shouldReturn('New description');
111
        $this->updatedOn()->shouldNotEqual($oldUpdatedOn);
112
113
        $this->shouldHavePublished(TaskEdited::class);
114
    }
115
116
    function its_progress_can_be_changed(TaskProgress $progress)
117
    {
118
        $oldUpdatedOn = $this->updatedOn();
119
120
        $this->changeProgress($progress);
121
122
        $this->progress()->shouldReturn($progress);
123
        $this->updatedOn()->shouldNotEqual($oldUpdatedOn);
124
125
        $this->shouldHavePublished(TaskProgressChanged::class);
126
    }
127
128
    function it_can_be_reassigned(MemberId $assignee)
129
    {
130
        $oldUpdatedOn = $this->updatedOn();
131
132
        $this->reassign($assignee);
133
134
        $this->assigneeId()->shouldReturn($assignee);
135
        $this->updatedOn()->shouldNotEqual($oldUpdatedOn);
136
137
        $this->shouldHavePublished(TaskReassigned::class);
138
    }
139
140
    function its_priority_can_be_changed(TaskPriority $priority)
141
    {
142
        $oldUpdatedOn = $this->updatedOn();
143
144
        $this->changePriority($priority);
145
146
        $this->priority()->shouldReturn($priority);
147
        $this->updatedOn()->shouldNotEqual($oldUpdatedOn);
148
149
        $this->shouldHavePublished(TaskPriorityChanged::class);
150
    }
151
152
    public function getMatchers()
153
    {
154
        return [
155
            'returnStatus' => function (TaskProgress $subject, $key) {
156
                return $subject->progress() === $key;
157
            },
158
        ];
159
    }
160
}
161