Passed
Push — master ( 7b7e33...6ff579 )
by Tomasz
04:38
created

DomainSpec::getMatchers()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 23
rs 8.5906
c 1
b 0
f 1
cc 5
eloc 12
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\Events\DomainEventInterface;
7
use Hexarchium\CoreDomain\Model\Domain\DomainId;
8
use Hexarchium\CoreDomain\Model\Domain\Entity\Domain;
9
use Hexarchium\CoreDomain\Model\Domain\Entity\Model;
10
use Hexarchium\CoreDomain\Model\Domain\Events\DomainCreated;
11
use Hexarchium\CoreDomain\Model\Domain\Events\ModelAdded;
12
use Hexarchium\CoreDomain\Model\Domain\Model\ModelId;
13
use PhpSpec\ObjectBehavior;
14
15
class DomainSpec extends ObjectBehavior
16
{
17
    function let(DomainId $domainId)
18
    {
19
        $domainId->beConstructedWith(['Domain']);
20
        $this->beConstructedWith($domainId);
21
    }
22
23
    function it_is_initializable()
24
    {
25
        $this->shouldHaveType(Domain::class);
26
        $this->shouldBeAnInstanceOf(AggregateRootInterface::class);
27
    }
28
29
    function it_should_have_id()
30
    {
31
        $this->getId()->shouldReturnAnInstanceOf(DomainId::class);
32
    }
33
34
    function it_should_contain_domain_events_after_creating()
35
    {
36
        $this->pullEvents()->shouldReturnArrayWithAtLeastInstanceOf(DomainCreated::class);
37
    }
38
39
    function it_should_add_model(Model $model)
40
    {
41
        $modelId = new ModelId(
42
            new DomainId('DomainId'), 'ModelId'
43
        );
44
        $model->getId()->willReturn($modelId);
45
        $this->addModel($model)->shouldReturn(null);
46
    }
47
48
    function it_should_generate_event_after_add_model(Model $model)
49
    {
50
        $modelId = new ModelId(
51
            new DomainId('DomainId'), 'ModelId'
52
        );
53
        $model->getId()->willReturn($modelId);
54
        $this->addModel($model);
55
        $this->pullEvents()->shouldReturnArrayWithAtLeastInstanceOf(ModelAdded::class);
56
    }
57
58
    function getMatchers()
59
    {
60
        return array(
61
            'returnArrayOfDomainEvents'        => function ($subject) {
62
                foreach ($subject as $element) {
63
                    if (!$element instanceof DomainEventInterface) {
64
                        return false;
65
                    }
66
                }
67
68
                return true;
69
            },
70
            'returnArrayWithAtLeastInstanceOf' => function ($subject, $eventClass) {
71
                foreach ($subject as $element) {
72
                    if ($element instanceof $eventClass) {
73
                        return true;
74
                    }
75
                }
76
77
                return false;
78
            }
79
        );
80
    }
81
}
82