Completed
Push — master ( 713312...49b74f )
by Ivannis Suárez
08:31
created

DomainEventTests::testStopPropagation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Cubiche/Event component.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Domain\EventPublisher\Tests\Units;
13
14
use Cubiche\Domain\EventPublisher\DomainEvent;
15
use Cubiche\Domain\EventPublisher\Tests\Fixtures\IncrementCounterEvent;
16
17
/**
18
 * DomainEvent class.
19
 *
20
 * Generated by TestGenerator on 2016-05-03 at 14:58:41.
21
 */
22
class DomainEventTests extends TestCase
23
{
24
    /**
25
     * Test eventName method.
26
     */
27
    public function testEventName()
28
    {
29
        $this
30
            ->given($event = new DomainEvent())
31
            ->then()
32
                ->string($event->eventName())
33
                    ->isEqualTo(DomainEvent::class)
34
                ->and()
35
                ->when($event = new DomainEvent('on_push'))
36
                ->then()
37
                    ->string($event->eventName())
38
                        ->isEqualTo('on_push')
39
        ;
40
    }
41
42
    /**
43
     * Test OccurredOn method.
44
     */
45
    public function testOccurredOn()
46
    {
47
        $this
48
            ->given($event = new DomainEvent())
49
            ->then()
50
                ->object($event->occurredOn())
51
                    ->isInstanceOf(\DateTime::class)
52
        ;
53
    }
54
55
    /**
56
     * Test StopPropagation method.
57
     */
58
    public function testStopPropagation()
59
    {
60
        $this
61
            ->given($event = new DomainEvent())
62
            ->then()
63
                ->boolean($event->isPropagationStopped())
64
                    ->isFalse()
65
                ->and()
66
                ->when($event->stopPropagation())
67
                ->then()
68
                    ->boolean($event->isPropagationStopped())
69
                        ->isTrue()
70
        ;
71
    }
72
73
    /**
74
     * Test SetPayload method.
75
     */
76
    public function testSetPayload()
77
    {
78
        $this
79
            ->given($event = new IncrementCounterEvent(5))
80
            ->then()
81
                ->object($event->occurredOn())
82
                    ->isInstanceOf(\DateTime::class)
83
                ->integer($event->step())
84
                    ->isEqualTo(5)
85
        ;
86
    }
87
88
    /**
89
     * Test ToArray method.
90
     */
91
    public function testToArray()
92
    {
93
        $this
94
            ->given($event = new IncrementCounterEvent(3))
95
            ->then()
96
                ->array($event->toArray())
97
                    ->child['metadata'](function ($metadata) {
98
                        $metadata
99
                            ->hasKey('occurredOn')
100
                            ->string['eventType']
101
                                ->isEqualTo(IncrementCounterEvent::class)
102
                        ;
103
                    })
104
                    ->child['payload'](function ($payload) {
105
                        $payload
106
                            ->isEqualTo(array(
107
                                'step' => 3,
108
                            ))
109
                        ;
110
                    })
111
        ;
112
    }
113
114
    /**
115
     * Test FromArray method.
116
     */
117
    public function testFromArray()
118
    {
119
        $this
120
            ->given($event = new IncrementCounterEvent(3))
121
            ->and($eventFromArray = IncrementCounterEvent::fromArray($event->toArray()))
122
            ->then()
123
                ->object($eventFromArray)
124
                    ->isInstanceOf(IncrementCounterEvent::class)
125
                ->object($event->occurredOn())
126
                    ->isEqualTo($eventFromArray->occurredOn())
127
                ->string($event->eventName())
128
                    ->isEqualTo($eventFromArray->eventName())
129
                ->integer($event->step())
130
                    ->isEqualTo($eventFromArray->step())
131
                ->boolean($event->isPropagationStopped())
132
                    ->isEqualTo($eventFromArray->isPropagationStopped())
133
        ;
134
    }
135
}
136