Completed
Pull Request — master (#130)
by Gorka
02:47
created

TaskSpec::it_gets_id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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\Participant;
17
use Kreta\TaskManager\Domain\Model\Project\Task\Task;
18
use Kreta\TaskManager\Domain\Model\Project\Task\TaskCreated;
19
use Kreta\TaskManager\Domain\Model\Project\Task\TaskEdited;
20
use Kreta\TaskManager\Domain\Model\Project\Task\TaskId;
21
use Kreta\TaskManager\Domain\Model\Project\Task\TaskPriority;
22
use Kreta\TaskManager\Domain\Model\Project\Task\TaskPriorityChanged;
23
use Kreta\TaskManager\Domain\Model\Project\Task\TaskProgress;
24
use Kreta\TaskManager\Domain\Model\Project\Task\TaskProgressChanged;
25
use Kreta\TaskManager\Domain\Model\Project\Task\TaskReassigned;
26
use Kreta\TaskManager\Domain\Model\Project\Task\TaskTitle;
27
use PhpSpec\ObjectBehavior;
28
29
class TaskSpec extends ObjectBehavior
30
{
31
    function let(TaskId $taskId, TaskTitle $title, Participant $creator, Participant $assignee, TaskPriority $priority)
32
    {
33
        $taskId->id()->willReturn('task-id');
34
        $this->beConstructedWith($taskId, $title, 'Description', $creator, $assignee, $priority);
35
    }
36
37
    function it_can_be_created(TaskId $taskId, TaskTitle $title, Participant $creator, Participant $assignee, TaskPriority $priority)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
38
    {
39
        $this->shouldHaveType(Task::class);
40
        $this->shouldHaveType(AggregateRoot::class);
41
42
        $this->id()->shouldReturn($taskId);
43
        $this->title()->shouldReturn($title);
44
        $this->description()->shouldReturn('Description');
45
        $this->creator()->shouldReturn($creator);
46
        $this->assignee()->shouldReturn($assignee);
47
        $this->priority()->shouldReturn($priority);
48
        $this->parentId()->shouldReturn(null);
49
        $this->progress()->shouldReturnStatus(TaskProgress::TODO);
50
        $this->createdOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
51
        $this->updatedOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
52
53
        $this->shouldHavePublished(TaskCreated::class);
54
55
        $this->__toString()->shouldReturn('task-id');
56
    }
57
58
    function it_can_be_created_as_a_subtask(TaskId $taskId,
59
                                            TaskTitle $title,
60
                                            Participant $creator,
61
                                            Participant $assignee,
62
                                            TaskPriority $priority,
63
                                            TaskId $parentId)
64
    {
65
        $this->beConstructedWith($taskId, $title, 'Description', $creator, $assignee, $priority, $parentId);
66
67
        $this->shouldHaveType(Task::class);
68
        $this->shouldHaveType(AggregateRoot::class);
69
70
        $this->id()->shouldReturn($taskId);
71
        $this->title()->shouldReturn($title);
72
        $this->description()->shouldReturn('Description');
73
        $this->creator()->shouldReturn($creator);
74
        $this->assignee()->shouldReturn($assignee);
75
        $this->priority()->shouldReturn($priority);
76
        $this->parentId()->shouldReturn($parentId);
77
        $this->progress()->shouldReturnStatus(TaskProgress::TODO);
78
        $this->createdOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
79
        $this->updatedOn()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
80
81
        $this->shouldHavePublished(TaskCreated::class);
82
83
        $this->__toString()->shouldReturn('task-id');
84
    }
85
86
    function it_can_be_edited(TaskTitle $title)
87
    {
88
        $oldUpdatedOn = $this->updatedOn();
89
90
        $this->edit($title, 'New description');
91
92
        $this->title()->shouldReturn($title);
93
        $this->description()->shouldReturn('New description');
94
        $this->updatedOn()->shouldNotEqual($oldUpdatedOn);
95
96
        $this->shouldHavePublished(TaskEdited::class);
97
    }
98
99
    function its_progress_can_be_changed(TaskProgress $progress)
100
    {
101
        $oldUpdatedOn = $this->updatedOn();
102
103
        $this->changeProgress($progress);
104
105
        $this->progress()->shouldReturn($progress);
106
        $this->updatedOn()->shouldNotEqual($oldUpdatedOn);
107
108
        $this->shouldHavePublished(TaskProgressChanged::class);
109
    }
110
111
    function it_can_be_reassigned(Participant $assignee)
112
    {
113
        $oldUpdatedOn = $this->updatedOn();
114
115
        $this->reassign($assignee);
116
117
        $this->assignee()->shouldReturn($assignee);
118
        $this->updatedOn()->shouldNotEqual($oldUpdatedOn);
119
120
        $this->shouldHavePublished(TaskReassigned::class);
121
    }
122
123
    function its_priority_can_be_changed(TaskPriority $priority)
124
    {
125
        $oldUpdatedOn = $this->updatedOn();
126
127
        $this->changePriority($priority);
128
129
        $this->priority()->shouldReturn($priority);
130
        $this->updatedOn()->shouldNotEqual($oldUpdatedOn);
131
132
        $this->shouldHavePublished(TaskPriorityChanged::class);
133
    }
134
135
    public function getMatchers()
136
    {
137
        return [
138
            'returnStatus' => function ($subject, $key) {
139
                return $subject->progress() === $key;
140
            },
141
        ];
142
    }
143
}
144