Completed
Push — master ( 1fe5d2...6a0fd3 )
by Tomasz
02:28
created

DomainSpec::getMatchers()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace spec\Hexarchium\CoreDomain\Model\Domain\Entity;
4
5
use Hexarchium\CoreDomain\Aggregate\AggregateRootInterface;
6
use Hexarchium\CoreDomain\Model\Domain\DomainId;
7
use Hexarchium\CoreDomain\Model\Domain\Entity\Domain;
8
use Hexarchium\CoreDomain\Model\Domain\Entity\Model;
9
use Hexarchium\CoreDomain\Model\Domain\Entity\UseCase;
10
use Hexarchium\CoreDomain\Model\Domain\Events\DomainCreated;
11
use Hexarchium\CoreDomain\Model\Domain\Events\ModelAdded;
12
use Hexarchium\CoreDomain\Model\Domain\Events\UseCaseAdded;
13
use Hexarchium\CoreDomain\Model\Domain\Model\ModelId;
14
use Hexarchium\CoreDomain\Model\Domain\UseCase\UseCaseId;
15
use PhpSpec\ObjectBehavior;
16
17
class DomainSpec extends ObjectBehavior
18
{
19
    function let(DomainId $domainId)
20
    {
21
        $domainId->beConstructedWith(['Domain']);
22
        $this->beConstructedWith($domainId);
23
    }
24
25
    function it_is_initializable()
26
    {
27
        $this->shouldHaveType(Domain::class);
28
        $this->shouldBeAnInstanceOf(AggregateRootInterface::class);
29
    }
30
31
    function it_should_have_id()
32
    {
33
        $this->getId()->shouldReturnAnInstanceOf(DomainId::class);
34
    }
35
36
    function it_should_contain_domain_events_after_creating()
37
    {
38
        $this->pullEvents()->shouldReturnArrayWithAtLeastInstanceOf(DomainCreated::class);
39
    }
40
41 View Code Duplication
    function it_should_add_model(Model $model)
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...
42
    {
43
        $modelId = new ModelId('ModelId');
44
        $model->getId()->willReturn($modelId);
45
        $model->setDomain($this->getWrappedObject())->shouldBeCalled();
46
47
        $this->addModel($model)->shouldReturn(null);
48
    }
49
50
    function it_should_generate_event_after_add_model(Model $model)
51
    {
52
        $modelId = new ModelId('ModelId');
53
        $model->getId()->willReturn($modelId);
54
        $model->setDomain($this->getWrappedObject())->shouldBeCalled();
55
56
        $this->addModel($model);
57
        $this->pullEvents()->shouldReturnArrayWithAtLeastInstanceOf(ModelAdded::class);
58
    }
59
60 View Code Duplication
    function it_should_add_use_case(UseCase $useCase)
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
    {
62
        $useCaseId = new UseCaseId('UseCaseId');
63
        $useCase->getId()->willReturn($useCaseId);
64
        $useCase->setDomain($this->getWrappedObject())->shouldBeCalled();
65
66
        $this->addUseCase($useCase)->shouldReturn(null);
67
    }
68
69 View Code Duplication
    function it_should_generate_event_after_add_use_case(UseCase $useCase)
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...
70
    {
71
        $useCaseId = new UseCaseId('UseCaseId');
72
        $useCase->getId()->willReturn($useCaseId);
73
        $useCase->setDomain($this->getWrappedObject())->shouldBeCalled();
74
75
        $this->addUseCase($useCase);
76
        $this->pullEvents()->shouldReturnArrayWithAtLeastInstanceOf(UseCaseAdded::class);
77
    }
78
79
    function getMatchers()
80
    {
81
        return array(
82
            'returnArrayWithAtLeastInstanceOf' => function ($subject, $eventClass) {
83
                foreach ($subject as $element) {
84
                    if ($element instanceof $eventClass) {
85
                        return true;
86
                    }
87
                }
88
89
                return false;
90
            }
91
        );
92
    }
93
}
94