Completed
Push — master ( 5c99b0...054645 )
by Ivannis Suárez
03:01
created

DomainEventTests::testFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 18
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 15
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 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