Completed
Push — master ( cdb55b...3f24cf )
by Gorka
9s
created

TaskOfIdHandlerSpec::it_serializes_task()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 10
rs 8.9713

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\TaskOfIdHandler;
17
use Kreta\TaskManager\Application\Query\Project\Task\TaskOfIdQuery;
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\Project\Project;
22
use Kreta\TaskManager\Domain\Model\Project\ProjectId;
23
use Kreta\TaskManager\Domain\Model\Project\ProjectRepository;
24
use Kreta\TaskManager\Domain\Model\Project\Task\Task;
25
use Kreta\TaskManager\Domain\Model\Project\Task\TaskDoesNotExistException;
26
use Kreta\TaskManager\Domain\Model\Project\Task\TaskId;
27
use Kreta\TaskManager\Domain\Model\Project\Task\TaskRepository;
28
use Kreta\TaskManager\Domain\Model\Project\Task\UnauthorizedTaskResourceException;
29
use Kreta\TaskManager\Domain\Model\User\UserId;
30
use PhpSpec\ObjectBehavior;
31
32
class TaskOfIdHandlerSpec extends ObjectBehavior
33
{
34
    function let(
35
        OrganizationRepository $organizationRepository,
36
        ProjectRepository $projectRepository,
37
        TaskRepository $repository,
38
        TaskDataTransformer $dataTransformer
39
    ) {
40
        $this->beConstructedWith($organizationRepository, $projectRepository, $repository, $dataTransformer);
41
    }
42
43
    function it_is_initializable()
44
    {
45
        $this->shouldHaveType(TaskOfIdHandler::class);
46
    }
47
48
    function it_serializes_task(
49
        TaskOfIdQuery $query,
50
        TaskRepository $repository,
51
        Task $task,
52
        ProjectId $projectId,
53
        ProjectRepository $projectRepository,
54
        Project $project,
55
        OrganizationId $organizationId,
56
        OrganizationRepository $organizationRepository,
57
        Organization $organization,
58
        TaskDataTransformer $dataTransformer
59
    ) {
60
        $query->taskId()->shouldBeCalled()->willReturn('task-id');
61
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn($task);
62
        $task->projectId()->shouldBeCalled()->willReturn($projectId);
63
        $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project);
64
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
65
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
66
        $query->userId()->shouldBeCalled()->willReturn('user-id');
67
        $organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true);
68
        $dataTransformer->write($task)->shouldBeCalled();
69
        $dataTransformer->read()->shouldBeCalled();
70
        $this->__invoke($query);
71
    }
72
73 View Code Duplication
    function it_does_not_serialize_task_because_the_task_does_not_exist(
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...
74
        TaskOfIdQuery $query,
75
        TaskRepository $repository
76
    ) {
77
        $query->taskId()->shouldBeCalled()->willReturn('task-id');
78
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled();
79
        $this->shouldThrow(TaskDoesNotExistException::class)->during__invoke($query);
80
    }
81
82 View Code Duplication
    function it_does_not_serialize_task_when_the_user_does_not_allowed(
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...
83
        TaskOfIdQuery $query,
84
        TaskRepository $repository,
85
        Task $task,
86
        ProjectId $projectId,
87
        ProjectRepository $projectRepository,
88
        Project $project,
89
        OrganizationId $organizationId,
90
        OrganizationRepository $organizationRepository,
91
        Organization $organization
92
    ) {
93
        $query->taskId()->shouldBeCalled()->willReturn('task-id');
94
        $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn($task);
95
        $task->projectId()->shouldBeCalled()->willReturn($projectId);
96
        $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project);
97
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
98
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
99
        $query->userId()->shouldBeCalled()->willReturn('user-id');
100
        $organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(false);
101
        $this->shouldThrow(UnauthorizedTaskResourceException::class)->during__invoke($query);
102
    }
103
}
104