Completed
Branch master (6ff579)
by Tomasz
06:50 queued 03:50
created

DomainSpec   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 11
lcom 0
cbo 4
dl 0
loc 67
rs 10
c 1
b 0
f 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 5 1
A it_is_initializable() 0 5 1
A it_should_have_id() 0 4 1
A it_should_contain_domain_events_after_creating() 0 4 1
A it_should_add_model() 0 8 1
A it_should_generate_event_after_add_model() 0 9 1
B getMatchers() 0 23 5
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