Completed
Push — master ( 690234...cb3625 )
by Gorka
02:59
created

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\Application\Organization;
14
15
use Kreta\TaskManager\Application\Organization\AddOwnerToOrganizationCommand;
16
use Kreta\TaskManager\Application\Organization\AddOwnerToOrganizationHandler;
17
use Kreta\TaskManager\Domain\Model\Organization\Organization;
18
use Kreta\TaskManager\Domain\Model\Organization\OrganizationDoesNotExistException;
19
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId;
20
use Kreta\TaskManager\Domain\Model\Organization\OrganizationRepository;
21
use Kreta\TaskManager\Domain\Model\Organization\Owner;
22
use Kreta\TaskManager\Domain\Model\Organization\OwnerId;
23
use Kreta\TaskManager\Domain\Model\Organization\UnauthorizedOrganizationActionException;
24
use Kreta\TaskManager\Domain\Model\User\UserId;
25
use PhpSpec\ObjectBehavior;
26
use Prophecy\Argument;
27
28
class AddOwnerToOrganizationHandlerSpec extends ObjectBehavior
29
{
30
    function let(OrganizationRepository $repository)
31
    {
32
        $this->beConstructedWith($repository);
33
    }
34
35
    function it_is_initializable()
36
    {
37
        $this->shouldHaveType(AddOwnerToOrganizationHandler::class);
38
    }
39
40 View Code Duplication
    function it_adds_owner_to_organization(
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...
41
        AddOwnerToOrganizationCommand $command,
42
        OrganizationRepository $repository,
43
        Organization $organization
44
    ) {
45
        $organizationId = OrganizationId::generate('organization-id');
46
47
        $command->organizationId()->shouldBeCalled()->willReturn('organization-id');
48
        $repository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
49
        $command->adderId()->shouldBeCalled()->willReturn('adder-id');
50
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
51
        $organization->isOwner(
52
            OwnerId::generate(UserId::generate('adder-id'), $organizationId)
53
        )->shouldBeCalled()->willReturn(true);
54
        $command->userId()->shouldBeCalled()->willReturn('user-id');
55
        $organization->addOwner(Argument::type(Owner::class))->shouldBeCalled();
56
        $repository->persist(Argument::type(Organization::class))->shouldBeCalled();
57
        $this->__invoke($command);
58
    }
59
60 View Code Duplication
    function it_does_not_add_owner_to_organization_because_organization_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...
61
        AddOwnerToOrganizationCommand $command,
62
        OrganizationRepository $repository
63
    ) {
64
        $command->organizationId()->shouldBeCalled()->willReturn('organization-id');
65
        $repository->organizationOfId(
66
            OrganizationId::generate('organization-id')
67
        )->shouldBeCalled()->willReturn(null);
68
        $this->shouldThrow(OrganizationDoesNotExistException::class)->during__invoke($command);
69
    }
70
71
    function it_does_not_add_owner_to_organization_because_it_is_not_allowed(
72
        AddOwnerToOrganizationCommand $command,
73
        OrganizationRepository $repository,
74
        Organization $organization
75
    ) {
76
        $organizationId = OrganizationId::generate('organization-id');
77
78
        $command->organizationId()->shouldBeCalled()->willReturn('organization-id');
79
        $repository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
80
        $command->adderId()->shouldBeCalled()->willReturn('adder-id');
81
        $organization->id()->shouldBeCalled()->willReturn($organizationId);
82
        $organization->isOwner(
83
            OwnerId::generate(UserId::generate('adder-id'), $organizationId)
84
        )->shouldBeCalled()->willReturn(false);
85
        $this->shouldThrow(UnauthorizedOrganizationActionException::class)->during__invoke($command);
86
    }
87
}
88