-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectionTest.php
133 lines (100 loc) · 3.5 KB
/
ConnectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace Phipe;
/**
* @package Phipe
*/
class ConnectionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|Connection
*/
protected $connection;
protected function setUp()
{
$this->connection = $this->getMockForAbstractClass(Connection::CLASS, ['127.0.0.1', 80]);
}
public function testIsEndOfFile()
{
$this->connection
->expects($this->once())
->method('getState')
->will($this->returnValue(Connection::STATE_EOF));
$result = $this->connection->isEndOfFile();
$this->assertTrue($result, 'Connection must indicate it has reached EOF');
}
public function testIsEndOfFileWithNonTerminated()
{
$this->connection
->expects($this->once())
->method('getState')
->will($this->returnValue(0));
$result = $this->connection->isEndOfFile();
$this->assertFalse($result, 'Connection must not indicate it has reached EOF');
}
public function testIsConnected()
{
$this->connection
->expects($this->once())
->method('getState')
->will($this->returnValue(Connection::STATE_CONNECTED));
$result = $this->connection->isConnected();
$this->assertTrue($result, 'Connection must indicate it is connected');
}
public function testIsConnectedWhenNotConnected()
{
$this->connection
->expects($this->once())
->method('getState')
->will($this->returnValue(0));
$result = $this->connection->isConnected();
$this->assertFalse($result, 'Connection must not indicate it is connected');
}
public function testIsDisconnected()
{
$this->connection
->expects($this->once())
->method('getState')
->will($this->returnValue(0));
$result = $this->connection->isDisconnected();
$this->assertTrue($result, 'Connection must indicate it is disconnected');
}
public function testIsDisconnectedWhenNotDisconnected()
{
$this->connection
->expects($this->once())
->method('getState')
->will($this->returnValue(Connection::STATE_CONNECTED));
$result = $this->connection->isDisconnected();
$this->assertFalse($result, 'Connection must not indicate it is disconnected');
}
public function testAttach()
{
$observer = $this->getMock(\SplObserver::CLASS);
$storage = $this->getMock(\SplObjectStorage::CLASS);
$storage->expects($this->once())
->method('attach')
->with($this->equalTo($observer));
$this->connection->setObservers($storage);
$this->connection->attach($observer);
}
public function testDetach()
{
$observer = $this->getMock(\SplObserver::CLASS);
$storage = $this->getMock(\SplObjectStorage::CLASS);
$storage->expects($this->once())
->method('detach')
->with($this->equalTo($observer));
$this->connection->setObservers($storage);
$this->connection->detach($observer);
}
public function testNotify()
{
$event = 'mock';
$observer = $this->getMock(\SplObserver::CLASS);
$observer->expects($this->once())
->method('update')
->with($this->connection, $event);
$this->connection->setObservers([$observer]);
$this->connection->notify($event);
}
}