Completed
Push — master ( f571ad...af881e )
by Gorka
10s
created

TaskDTODataTransformerSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 58
rs 10
c 1
b 0
f 0
wmc 3
lcom 0
cbo 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 5 1
B it_transform_task_to_plain_dto() 0 44 1
A it_does_not_transformer_when_task_is_null() 0 4 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\Application\DataTransformer\Project\Task;
14
15
use Kreta\TaskManager\Application\DataTransformer\Project\Task\TaskDataTransformer;
16
use Kreta\TaskManager\Application\DataTransformer\Project\Task\TaskDTODataTransformer;
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\TaskId;
20
use Kreta\TaskManager\Domain\Model\Project\Task\TaskPriority;
21
use Kreta\TaskManager\Domain\Model\Project\Task\TaskProgress;
22
use Kreta\TaskManager\Domain\Model\Project\Task\TaskTitle;
23
use PhpSpec\ObjectBehavior;
24
25
class TaskDTODataTransformerSpec extends ObjectBehavior
26
{
27
    function it_is_initializable()
28
    {
29
        $this->shouldHaveType(TaskDTODataTransformer::class);
30
        $this->shouldImplement(TaskDataTransformer::class);
31
    }
32
33
    function it_transform_task_to_plain_dto(
34
        Task $task,
35
        TaskId $taskId,
36
        TaskTitle $title,
37
        ProjectId $projectId,
38
        TaskPriority $priority,
39
        TaskProgress $progress,
40
        \DateTimeImmutable $createdOn,
41
        \DateTimeImmutable $updatedOn,
42
        TaskId $parentId
43
    ) {
44
        $task->id()->shouldBeCalled()->willReturn($taskId);
45
        $taskId->id()->shouldBeCalled()->willReturn('task-id');
46
        $task->title()->shouldBeCalled()->willReturn($title);
47
        $title->title()->shouldBeCalled()->willReturn('The task title');
48
        $task->priority()->shouldBeCalled()->willReturn($priority);
49
        $priority->priority()->shouldBeCalled()->willReturn('low');
50
        $task->progress()->shouldBeCalled()->willReturn($progress);
51
        $progress->progress()->shouldBeCalled()->willReturn('todo');
52
        $task->description()->shouldBeCalled()->willReturn('The task description');
53
        $task->createdOn()->shouldBeCalled()->willReturn($createdOn);
54
        $task->updatedOn()->shouldBeCalled()->willReturn($updatedOn);
55
        $task->projectId()->shouldBeCalled()->willReturn($projectId);
56
        $projectId->id()->shouldBeCalled()->willReturn('project-id');
57
        $task->parentId()->shouldBeCalled()->willReturn($parentId);
58
        $parentId->id()->shouldBeCalled()->willReturn('parent-id');
59
60
        $createdOn->format('Y-m-d')->shouldBeCalled()->willReturn('2016-10-20');
61
        $updatedOn->format('Y-m-d')->shouldBeCalled()->willReturn('2016-10-22');
62
63
        $this->write($task);
64
65
        $this->read()->shouldReturn([
66
            'id'          => 'task-id',
67
            'title'       => 'The task title',
68
            'priority'    => 'low',
69
            'progress'    => 'todo',
70
            'description' => 'The task description',
71
            'created_on'  => '2016-10-20',
72
            'updated_on'  => '2016-10-22',
73
            'project_id'  => 'project-id',
74
            'parent_id'   => 'parent-id',
75
        ]);
76
    }
77
78
    function it_does_not_transformer_when_task_is_null()
79
    {
80
        $this->read()->shouldReturn([]);
81
    }
82
}
83