|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PamiModuleTest\Listener; |
|
4
|
|
|
|
|
5
|
|
|
use PamiModule\Listener\ConnectionStatusListener; |
|
6
|
|
|
use Zend\EventManager\Event; |
|
7
|
|
|
|
|
8
|
|
|
class ConnectionStatusListenerTest extends \PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testAttach() |
|
11
|
|
|
{ |
|
12
|
|
|
$events = $this->getMockBuilder('Zend\\EventManager\\EventManagerInterface')->getMock(); |
|
13
|
|
|
|
|
14
|
|
|
$events->expects(static::atLeast(4)) |
|
15
|
|
|
->method('attach') |
|
16
|
|
|
->withConsecutive( |
|
17
|
|
|
['connect.pre'], |
|
18
|
|
|
['disconnect.pre'], |
|
19
|
|
|
['process.pre'], |
|
20
|
|
|
['sendAction.pre'] |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
$listener = new ConnectionStatusListener(); |
|
24
|
|
|
$listener->attach($events); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testOnConnect() |
|
28
|
|
|
{ |
|
29
|
|
|
$listener = new ConnectionStatusListener(); |
|
30
|
|
|
|
|
31
|
|
|
$event = new Event('connect.pre'); |
|
32
|
|
|
$listener->onConnect($event); |
|
33
|
|
|
static::assertFalse($event->propagationIsStopped()); |
|
34
|
|
|
|
|
35
|
|
|
$event = new Event('connect.pre'); |
|
36
|
|
|
$listener->onConnect($event); |
|
37
|
|
|
static::assertTrue($event->propagationIsStopped()); |
|
38
|
|
|
|
|
39
|
|
|
$event = new Event('connect.pre'); |
|
40
|
|
|
$listener->onConnect($event); |
|
41
|
|
|
static::assertTrue($event->propagationIsStopped()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testOnDisconnect() |
|
45
|
|
|
{ |
|
46
|
|
|
$listener = new ConnectionStatusListener(); |
|
47
|
|
|
|
|
48
|
|
|
$event = new Event('disconnect.pre'); |
|
49
|
|
|
$listener->onDisconnect($event); |
|
50
|
|
|
static::assertTrue($event->propagationIsStopped()); |
|
51
|
|
|
|
|
52
|
|
|
$listener->onConnect(new Event('connect.pre')); |
|
53
|
|
|
|
|
54
|
|
|
$event = new Event('disconnect.pre'); |
|
55
|
|
|
$listener->onDisconnect($event); |
|
56
|
|
|
static::assertFalse($event->propagationIsStopped()); |
|
57
|
|
|
|
|
58
|
|
|
$event = new Event('disconnect.pre'); |
|
59
|
|
|
$listener->onDisconnect($event); |
|
60
|
|
|
static::assertTrue($event->propagationIsStopped()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testOnProcess() |
|
64
|
|
|
{ |
|
65
|
|
|
$client = $this->getMockBuilder('PamiModule\\Service\\Client') |
|
66
|
|
|
->disableOriginalConstructor() |
|
67
|
|
|
->setMethods(['connect']) |
|
68
|
|
|
->getMock(); |
|
69
|
|
|
$listener = new ConnectionStatusListener(); |
|
70
|
|
|
|
|
71
|
|
|
$client->expects(static::once()) |
|
72
|
|
|
->method('connect'); |
|
73
|
|
|
|
|
74
|
|
|
$event = new Event('process.pre', $client); |
|
75
|
|
|
$listener->onProcess($event); |
|
76
|
|
|
|
|
77
|
|
|
// Should receive a connect event |
|
78
|
|
|
$event = new Event('connect.pre'); |
|
79
|
|
|
$listener->onConnect($event); |
|
80
|
|
|
|
|
81
|
|
|
$event = new Event('process.pre', $client); |
|
82
|
|
|
$listener->onProcess($event); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testOnSendAction() |
|
86
|
|
|
{ |
|
87
|
|
|
$client = $this->getMockBuilder('PamiModule\\Service\\Client') |
|
88
|
|
|
->disableOriginalConstructor() |
|
89
|
|
|
->setMethods(['connect']) |
|
90
|
|
|
->getMock(); |
|
91
|
|
|
$listener = new ConnectionStatusListener(); |
|
92
|
|
|
|
|
93
|
|
|
$client->expects(static::once()) |
|
94
|
|
|
->method('connect'); |
|
95
|
|
|
|
|
96
|
|
|
$event = new Event('sendAction.pre', $client); |
|
97
|
|
|
$listener->onSendAction($event); |
|
98
|
|
|
|
|
99
|
|
|
// Should receive a connect event |
|
100
|
|
|
$event = new Event('connect.pre'); |
|
101
|
|
|
$listener->onConnect($event); |
|
102
|
|
|
|
|
103
|
|
|
$event = new Event('sendAction.pre', $client); |
|
104
|
|
|
$listener->onSendAction($event); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|