Completed
Pull Request — master (#178)
by Beñat
03:05
created

AggregateRootEventRecorderSpec::it_post_persist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
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
namespace Spec\Kreta\SharedKernel\Infrastructure\Event\SimpleBus\EventRecorder\Doctrine\ORM;
14
15
use Doctrine\Common\EventSubscriber;
16
use Doctrine\ORM\Event\LifecycleEventArgs;
17
use Doctrine\ORM\Events;
18
use Kreta\SharedKernel\Domain\Model\AggregateRoot;
19
use Kreta\SharedKernel\Domain\Model\DomainEvent;
20
use Kreta\SharedKernel\Infrastructure\Event\SimpleBus\EventRecorder\Doctrine\ORM\AggregateRootEventRecorder;
21
use PhpSpec\ObjectBehavior;
22
use SimpleBus\Message\Recorder\ContainsRecordedMessages;
23
24
class AggregateRootEventRecorderSpec extends ObjectBehavior
25
{
26
    function it_is_initializable()
27
    {
28
        $this->shouldHaveType(AggregateRootEventRecorder::class);
29
        $this->shouldImplement(EventSubscriber::class);
30
        $this->shouldImplement(ContainsRecordedMessages::class);
31
    }
32
33
    function it_gets_subscribed_events()
34
    {
35
        $this->getSubscribedEvents()->shouldReturn([
36
            Events::postPersist,
37
            Events::postUpdate,
38
            Events::postRemove,
39
        ]);
40
    }
41
42 View Code Duplication
    function it_post_persist(LifecycleEventArgs $event, AggregateRoot $aggregateRoot)
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...
43
    {
44
        $event->getEntity()->shouldBeCalled()->willReturn($aggregateRoot);
45
        $aggregateRoot->recordedEvents()->shouldBeCalled()->willReturn([]);
46
        $aggregateRoot->clearEvents()->shouldBeCalled();
47
        $this->postPersist($event);
48
    }
49
50 View Code Duplication
    function it_post_update(LifecycleEventArgs $event, AggregateRoot $aggregateRoot)
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...
51
    {
52
        $event->getEntity()->shouldBeCalled()->willReturn($aggregateRoot);
53
        $aggregateRoot->recordedEvents()->shouldBeCalled()->willReturn([]);
54
        $aggregateRoot->clearEvents()->shouldBeCalled();
55
        $this->postUpdate($event);
56
    }
57
58 View Code Duplication
    function it_post_remove(LifecycleEventArgs $event, AggregateRoot $aggregateRoot)
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...
59
    {
60
        $event->getEntity()->shouldBeCalled()->willReturn($aggregateRoot);
61
        $aggregateRoot->recordedEvents()->shouldBeCalled()->willReturn([]);
62
        $aggregateRoot->clearEvents()->shouldBeCalled();
63
        $this->postRemove($event);
64
    }
65
66
    function it_manage_recorded_events(
67
        LifecycleEventArgs $event,
68
        AggregateRoot $aggregateRoot,
69
        DomainEvent $domainEvent
70
    ) {
71
        $event->getEntity()->shouldBeCalled()->willReturn($aggregateRoot);
72
        $aggregateRoot->recordedEvents()->shouldBeCalled()->willReturn([$domainEvent]);
73
        $aggregateRoot->clearEvents()->shouldBeCalled();
74
        $this->postPersist($event);
75
        $this->recordedMessages()->shouldBeArray();
76
        $this->recordedMessages()->shouldHaveCount(1);
77
        $this->eraseMessages();
78
        $this->recordedMessages()->shouldHaveCount(0);
79
    }
80
}
81