Code Duplication    Length = 80-85 lines in 2 locations

TaskManager/tests/Spec/Kreta/TaskManager/Application/Query/Organization/OrganizationMemberOfIdHandlerSpec.php 1 location

@@ 28-112 (lines=85) @@
25
use Kreta\TaskManager\Domain\Model\User\UserId;
26
use PhpSpec\ObjectBehavior;
27
28
class OrganizationMemberOfIdHandlerSpec extends ObjectBehavior
29
{
30
    function let(OrganizationRepository $repository, MemberDataTransformer $dataTransformer)
31
    {
32
        $this->beConstructedWith($repository, $dataTransformer);
33
    }
34
35
    function it_is_initializable()
36
    {
37
        $this->shouldHaveType(OrganizationMemberOfIdHandler::class);
38
    }
39
40
    function it_serializes_organization_member(
41
        OrganizationMemberOfIdQuery $query,
42
        OrganizationRepository $repository,
43
        Organization $organization,
44
        MemberDataTransformer $dataTransformer,
45
        OrganizationMember $organizationMember
46
    ) {
47
        $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
48
        $repository->organizationOfId(
49
            OrganizationId::generate('organization-id')
50
        )->shouldBeCalled()->willReturn($organization);
51
        $query->userId()->shouldBeCalled()->willReturn('user-id');
52
        $organization->isOrganizationMember(
53
            UserId::generate('user-id')
54
        )->shouldBeCalled()->willReturn(true);
55
        $query->memberId()->shouldBeCalled()->willReturn('member-id');
56
        $organization->isOrganizationMember(
57
            UserId::generate('member-id')
58
        )->shouldBeCalled()->willReturn(true);
59
        $organization->organizationMember(UserId::generate('member-id'))
60
            ->shouldBeCalled()->willReturn($organizationMember);
61
        $dataTransformer->write($organizationMember)->shouldBeCalled();
62
        $dataTransformer->read()->shouldBeCalled();
63
        $this->__invoke($query);
64
    }
65
66
    function it_does_not_serialize_organization_member_because_the_organization_does_not_exist(
67
        OrganizationMemberOfIdQuery $query,
68
        OrganizationRepository $repository
69
    ) {
70
        $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
71
        $repository->organizationOfId(
72
            OrganizationId::generate('organization-id')
73
        )->shouldBeCalled()->willReturn(null);
74
        $this->shouldThrow(OrganizationDoesNotExistException::class)->during__invoke($query);
75
    }
76
77
    function it_does_not_serialize_organization_member_because_it_does_not_exist(
78
        OrganizationMemberOfIdQuery $query,
79
        OrganizationRepository $repository,
80
        Organization $organization
81
    ) {
82
        $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
83
        $repository->organizationOfId(
84
            OrganizationId::generate('organization-id')
85
        )->shouldBeCalled()->willReturn($organization);
86
        $query->userId()->shouldBeCalled()->willReturn('user-id');
87
        $organization->isOrganizationMember(
88
            UserId::generate('user-id')
89
        )->shouldBeCalled()->willReturn(true);
90
        $query->memberId()->shouldBeCalled()->willReturn('member-id');
91
        $organization->isOrganizationMember(
92
            UserId::generate('member-id')
93
        )->shouldBeCalled()->willReturn(false);
94
        $this->shouldThrow(OrganizationMemberDoesNotExistException::class)->during__invoke($query);
95
    }
96
97
    function it_does_not_serialize_organization_member_when_the_user_does_not_allow_to_perform_this_action(
98
        OrganizationMemberOfIdQuery $query,
99
        OrganizationRepository $repository,
100
        Organization $organization
101
    ) {
102
        $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
103
        $repository->organizationOfId(
104
            OrganizationId::generate('organization-id')
105
        )->shouldBeCalled()->willReturn($organization);
106
        $query->userId()->shouldBeCalled()->willReturn('user-id');
107
        $organization->isOrganizationMember(
108
            UserId::generate('user-id')
109
        )->shouldBeCalled()->willReturn(false);
110
        $this->shouldThrow(UnauthorizedOrganizationActionException::class)->during__invoke($query);
111
    }
112
}
113

TaskManager/tests/Spec/Kreta/TaskManager/Application/Query/Organization/OwnerOfIdHandlerSpec.php 1 location

@@ 28-107 (lines=80) @@
25
use Kreta\TaskManager\Domain\Model\User\UserId;
26
use PhpSpec\ObjectBehavior;
27
28
class OwnerOfIdHandlerSpec extends ObjectBehavior
29
{
30
    function let(OrganizationRepository $repository, MemberDataTransformer $dataTransformer)
31
    {
32
        $this->beConstructedWith($repository, $dataTransformer);
33
    }
34
35
    function it_is_initializable()
36
    {
37
        $this->shouldHaveType(OwnerOfIdHandler::class);
38
    }
39
40
    function it_serializes_owner(
41
        OwnerOfIdQuery $query,
42
        OrganizationRepository $repository,
43
        Organization $organization,
44
        MemberDataTransformer $dataTransformer,
45
        Owner $owner
46
    ) {
47
        $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
48
        $repository->organizationOfId(
49
            OrganizationId::generate('organization-id')
50
        )->shouldBeCalled()->willReturn($organization);
51
        $query->userId()->shouldBeCalled()->willReturn('user-id');
52
        $organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true);
53
        $query->ownerId()->shouldBeCalled()->willReturn('owner-id');
54
        $organization->isOwner(
55
            UserId::generate('owner-id')
56
        )->shouldBeCalled()->willReturn(true);
57
        $organization->owner(UserId::generate('owner-id'))
58
            ->shouldBeCalled()->willReturn($owner);
59
60
        $dataTransformer->write($owner)->shouldBeCalled();
61
        $dataTransformer->read()->shouldBeCalled();
62
        $this->__invoke($query);
63
    }
64
65
    function it_does_not_serialize_owner_because_the_organization_does_not_exist(
66
        OwnerOfIdQuery $query,
67
        OrganizationRepository $repository
68
    ) {
69
        $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
70
        $repository->organizationOfId(
71
            OrganizationId::generate('organization-id')
72
        )->shouldBeCalled()->willReturn(null);
73
        $this->shouldThrow(OrganizationDoesNotExistException::class)->during__invoke($query);
74
    }
75
76
    function it_does_not_serialize_owner_because_it_does_not_exist(
77
        OwnerOfIdQuery $query,
78
        OrganizationRepository $repository,
79
        Organization $organization
80
    ) {
81
        $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
82
        $repository->organizationOfId(
83
            OrganizationId::generate('organization-id')
84
        )->shouldBeCalled()->willReturn($organization);
85
        $query->userId()->shouldBeCalled()->willReturn('user-id');
86
        $organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(true);
87
        $query->ownerId()->shouldBeCalled()->willReturn('owner-id');
88
        $organization->isOwner(
89
            UserId::generate('owner-id')
90
        )->shouldBeCalled()->willReturn(false);
91
        $this->shouldThrow(OwnerDoesNotExistException::class)->during__invoke($query);
92
    }
93
94
    function it_does_not_serialize_owner_when_the_user_does_not_allow_to_perform_this_action(
95
        OwnerOfIdQuery $query,
96
        OrganizationRepository $repository,
97
        Organization $organization
98
    ) {
99
        $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
100
        $repository->organizationOfId(
101
            OrganizationId::generate('organization-id')
102
        )->shouldBeCalled()->willReturn($organization);
103
        $query->userId()->shouldBeCalled()->willReturn('user-id');
104
        $organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(false);
105
        $this->shouldThrow(UnauthorizedOrganizationActionException::class)->during__invoke($query);
106
    }
107
}
108