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
|
|
|
|