1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Lug package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Lug\Component\Resource\Tests\Domain; |
13
|
|
|
|
14
|
|
|
use Lug\Component\Resource\Domain\DomainEvent; |
15
|
|
|
use Lug\Component\Resource\Model\ResourceInterface; |
16
|
|
|
use Symfony\Component\EventDispatcher\Event; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class DomainEventTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var DomainEvent |
26
|
|
|
*/ |
27
|
|
|
private $domainEvent; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|ResourceInterface |
31
|
|
|
*/ |
32
|
|
|
private $resource; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $action; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
protected function setUp() |
43
|
|
|
{ |
44
|
|
|
$this->resource = $this->createResourceMock(); |
45
|
|
|
$this->action = 'action'; |
46
|
|
|
|
47
|
|
|
$this->domainEvent = new DomainEvent($this->resource, $this->action); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testInheritance() |
51
|
|
|
{ |
52
|
|
|
$this->assertInstanceOf(Event::class, $this->domainEvent); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testDefaultState() |
56
|
|
|
{ |
57
|
|
|
$this->assertSame($this->resource, $this->domainEvent->getResource()); |
58
|
|
|
$this->assertSame($this->action, $this->domainEvent->getAction()); |
59
|
|
|
$this->assertNull($this->domainEvent->getData()); |
60
|
|
|
$this->assertNull($this->domainEvent->getStatusCode()); |
61
|
|
|
$this->assertNull($this->domainEvent->getMessageType()); |
62
|
|
|
$this->assertNull($this->domainEvent->getMessage()); |
63
|
|
|
$this->assertFalse($this->domainEvent->isStopped()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testInitialState() |
67
|
|
|
{ |
68
|
|
|
$this->domainEvent = new DomainEvent($this->resource, $this->action, $data = new \stdClass()); |
69
|
|
|
|
70
|
|
|
$this->assertSame($this->resource, $this->domainEvent->getResource()); |
71
|
|
|
$this->assertSame($this->action, $this->domainEvent->getAction()); |
72
|
|
|
$this->assertSame($data, $this->domainEvent->getData()); |
73
|
|
|
$this->assertNull($this->domainEvent->getStatusCode()); |
74
|
|
|
$this->assertNull($this->domainEvent->getMessageType()); |
75
|
|
|
$this->assertNull($this->domainEvent->getMessage()); |
76
|
|
|
$this->assertFalse($this->domainEvent->isStopped()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testData() |
80
|
|
|
{ |
81
|
|
|
$this->domainEvent->setData($data = new \stdClass()); |
82
|
|
|
|
83
|
|
|
$this->assertSame($data, $this->domainEvent->getData()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testStatusCode() |
87
|
|
|
{ |
88
|
|
|
$this->domainEvent->setStatusCode($statusCode = Response::HTTP_CREATED); |
89
|
|
|
|
90
|
|
|
$this->assertSame($statusCode, $this->domainEvent->getStatusCode()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testMessageType() |
94
|
|
|
{ |
95
|
|
|
$this->domainEvent->setMessageType($messageType = 'message_type'); |
96
|
|
|
|
97
|
|
|
$this->assertSame($messageType, $this->domainEvent->getMessageType()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testMessage() |
101
|
|
|
{ |
102
|
|
|
$this->domainEvent->setMessage($message = 'message'); |
103
|
|
|
|
104
|
|
|
$this->assertSame($message, $this->domainEvent->getMessage()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testStopped() |
108
|
|
|
{ |
109
|
|
|
$this->domainEvent->setStopped(true); |
110
|
|
|
|
111
|
|
|
$this->assertTrue($this->domainEvent->isStopped()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface |
116
|
|
|
*/ |
117
|
|
|
private function createResourceMock() |
118
|
|
|
{ |
119
|
|
|
return $this->createMock(ResourceInterface::class); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|