ConnectionStatusListenerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 4
dl 0
loc 99
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testAttach() 0 16 1
A testOnConnect() 0 16 1
A testOnDisconnect() 0 18 1
A testOnProcess() 0 21 1
A testOnSendAction() 0 21 1
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