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 OccurredOn method. |
26
|
|
|
*/ |
27
|
|
|
public function testOccurredOn() |
28
|
|
|
{ |
29
|
|
|
$this |
30
|
|
|
->given($event = new DomainEvent()) |
31
|
|
|
->then() |
32
|
|
|
->object($event->occurredOn()) |
33
|
|
|
->isInstanceOf(\DateTime::class) |
34
|
|
|
; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Test SetPayload method. |
39
|
|
|
*/ |
40
|
|
|
public function testSetPayload() |
41
|
|
|
{ |
42
|
|
|
$this |
43
|
|
|
->given($event = new IncrementCounterEvent(5)) |
44
|
|
|
->then() |
45
|
|
|
->object($event->occurredOn()) |
46
|
|
|
->isInstanceOf(\DateTime::class) |
47
|
|
|
->integer($event->step()) |
48
|
|
|
->isEqualTo(5) |
49
|
|
|
; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Test ToArray method. |
54
|
|
|
*/ |
55
|
|
|
public function testToArray() |
56
|
|
|
{ |
57
|
|
|
$this |
58
|
|
|
->given($event = new IncrementCounterEvent(3)) |
59
|
|
|
->then() |
60
|
|
|
->array($event->toArray()) |
61
|
|
|
->string['eventType'] |
62
|
|
|
->isEqualTo(IncrementCounterEvent::class) |
63
|
|
|
->child['metadata'](function ($metadata) { |
64
|
|
|
$metadata |
65
|
|
|
->hasKey('occurredOn') |
66
|
|
|
; |
67
|
|
|
}) |
68
|
|
|
->child['payload'](function ($payload) { |
69
|
|
|
$payload |
70
|
|
|
->isEqualTo(array( |
71
|
|
|
'step' => 3, |
72
|
|
|
)) |
73
|
|
|
; |
74
|
|
|
}) |
75
|
|
|
; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Test FromArray method. |
80
|
|
|
*/ |
81
|
|
|
public function testFromArray() |
82
|
|
|
{ |
83
|
|
|
$this |
84
|
|
|
->given($event = new IncrementCounterEvent(3)) |
85
|
|
|
->and($eventFromArray = IncrementCounterEvent::fromArray($event->toArray())) |
86
|
|
|
->then() |
87
|
|
|
->object($eventFromArray) |
88
|
|
|
->isInstanceOf(IncrementCounterEvent::class) |
89
|
|
|
->object($event->occurredOn()) |
90
|
|
|
->isEqualTo($eventFromArray->occurredOn()) |
91
|
|
|
->string($event->eventName()) |
92
|
|
|
->isEqualTo($eventFromArray->eventName()) |
93
|
|
|
->integer($event->step()) |
94
|
|
|
->isEqualTo($eventFromArray->step()) |
95
|
|
|
->boolean($event->isPropagationStopped()) |
96
|
|
|
->isEqualTo($eventFromArray->isPropagationStopped()) |
97
|
|
|
; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|