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\Application\Command\Project\Task; |
16
|
|
|
|
17
|
|
|
use Kreta\TaskManager\Application\Command\Project\Task\ChangeTaskProgressCommand; |
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\TaskProgress; |
28
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\TaskRepository; |
29
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\UnauthorizedTaskActionException; |
30
|
|
|
use Kreta\TaskManager\Domain\Model\User\UserId; |
31
|
|
|
use PhpSpec\ObjectBehavior; |
32
|
|
|
use Prophecy\Argument; |
33
|
|
|
|
34
|
|
|
class ChangeTaskProgressHandlerSpec extends ObjectBehavior |
35
|
|
|
{ |
36
|
|
|
private $id; |
37
|
|
|
private $progress; |
38
|
|
|
private $editorId; |
39
|
|
|
|
40
|
|
View Code Duplication |
function let( |
|
|
|
|
41
|
|
|
OrganizationRepository $organizationRepository, |
42
|
|
|
ProjectRepository $projectRepository, |
43
|
|
|
TaskRepository $taskRepository, |
44
|
|
|
ChangeTaskProgressCommand $command |
45
|
|
|
) { |
46
|
|
|
$this->beConstructedWith($organizationRepository, $projectRepository, $taskRepository); |
47
|
|
|
|
48
|
|
|
$command->id()->shouldBeCalled()->willReturn('task-id'); |
49
|
|
|
$command->progress()->shouldBeCalled()->willReturn('doing'); |
50
|
|
|
$command->editorId()->shouldBeCalled()->willReturn('editor-id'); |
51
|
|
|
|
52
|
|
|
$this->id = TaskId::generate('task-id'); |
53
|
|
|
$this->progress = new TaskProgress('doing'); |
54
|
|
|
$this->editorId = UserId::generate('editor-id'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
function it_does_not_change_task_progress_when_the_task_does_not_exist( |
58
|
|
|
TaskRepository $taskRepository, |
59
|
|
|
ChangeTaskProgressCommand $command |
60
|
|
|
) { |
61
|
|
|
$taskRepository->taskOfId($this->id)->shouldBeCalled()->willReturn(null); |
62
|
|
|
$this->shouldThrow(TaskDoesNotExistException::class)->during__invoke($command); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function it_does_not_change_task_progress_when_the_editor_is_not_an_organization_member( |
66
|
|
|
TaskRepository $taskRepository, |
67
|
|
|
Task $task, |
68
|
|
|
OrganizationRepository $organizationRepository, |
69
|
|
|
ProjectRepository $projectRepository, |
70
|
|
|
Project $project, |
71
|
|
|
ProjectId $projectId, |
72
|
|
|
ChangeTaskProgressCommand $command, |
73
|
|
|
OrganizationId $organizationId, |
74
|
|
|
Organization $organization |
75
|
|
|
) { |
76
|
|
|
$taskRepository->taskOfId($this->id)->shouldBeCalled()->willReturn($task); |
77
|
|
|
$task->projectId()->shouldBeCalled()->willReturn($projectId); |
78
|
|
|
$projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project); |
79
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
80
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
81
|
|
|
$organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false); |
82
|
|
|
$this->shouldThrow(UnauthorizedTaskActionException::class)->during__invoke($command); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
function it_changes_task_progress( |
86
|
|
|
OrganizationRepository $organizationRepository, |
87
|
|
|
ProjectRepository $projectRepository, |
88
|
|
|
TaskRepository $taskRepository, |
89
|
|
|
ChangeTaskProgressCommand $command, |
90
|
|
|
Task $task, |
91
|
|
|
Project $project, |
92
|
|
|
ProjectId $projectId, |
93
|
|
|
OrganizationId $organizationId, |
94
|
|
|
Organization $organization |
95
|
|
|
) { |
96
|
|
|
$taskRepository->taskOfId($this->id)->shouldBeCalled()->willReturn($task); |
97
|
|
|
$task->projectId()->shouldBeCalled()->willReturn($projectId); |
98
|
|
|
$projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project); |
99
|
|
|
$project->organizationId()->shouldBeCalled()->willReturn($organizationId); |
100
|
|
|
$organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); |
101
|
|
|
$organization->isOrganizationMember($this->editorId)->shouldBeCalled()->willReturn(true); |
102
|
|
|
$task->changeProgress($this->progress)->shouldBeCalled(); |
103
|
|
|
$taskRepository->persist(Argument::type(Task::class))->shouldBeCalled(); |
104
|
|
|
$this->__invoke($command); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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.