AggregateRootSpec   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 6 1
A it_is_initializable() 0 4 1
A it_gets_recorded_events() 0 4 1
A it_gets_id() 0 4 1
A it_publishes_an_event_like_event_sourcing() 0 7 1
A it_publishes_an_event_like_cqrs() 0 7 1
A it_reconstitutes_the_aggregate_root() 0 6 1
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
declare(strict_types=1);
14
15
namespace Spec\Kreta\SharedKernel\Domain\Model;
16
17
use Kreta\SharedKernel\Domain\Model\AggregateRoot;
18
use Kreta\SharedKernel\Domain\Model\Identity\Id;
19
use Kreta\SharedKernel\Event\Stream;
20
use Kreta\SharedKernel\Event\StreamName;
21
use Kreta\SharedKernel\Tests\Double\Domain\Model\AggregateRootStub;
22
use PhpSpec\ObjectBehavior;
23
24
class AggregateRootSpec extends ObjectBehavior
25
{
26
    function let(Id $id)
27
    {
28
        $this->beAnInstanceOf(AggregateRootStub::class);
29
30
        $this->beConstructedWith($id);
31
    }
32
33
    function it_is_initializable()
34
    {
35
        $this->shouldHaveType(AggregateRoot::class);
36
    }
37
38
    function it_gets_recorded_events()
39
    {
40
        $this->recordedEvents()->shouldBeArray();
41
    }
42
43
    function it_gets_id(Id $id)
44
    {
45
        $this->id()->shouldReturn($id);
46
    }
47
48
    function it_publishes_an_event_like_event_sourcing()
49
    {
50
        $this->recordedEvents()->shouldHaveCount(0);
51
        $this->foo();
52
        $this->recordedEvents()->shouldHaveCount(1);
53
        $this->property()->shouldReturn('foo');
54
    }
55
56
    function it_publishes_an_event_like_cqrs()
57
    {
58
        $this->recordedEvents()->shouldHaveCount(0);
59
        $this->bar();
60
        $this->recordedEvents()->shouldHaveCount(1);
61
        $this->property()->shouldReturn('bar');
62
    }
63
64
    function it_reconstitutes_the_aggregate_root(Stream $stream, StreamName $streamName, Id $aggregateId)
65
    {
66
        $stream->name()->shouldBeCalled()->willReturn($streamName);
67
        $streamName->aggregateId()->shouldBeCalled()->willReturn($aggregateId);
68
        $this::reconstitute($stream)->shouldReturnAnInstanceOf(AggregateRoot::class);
69
    }
70
}
71