| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
namespace Ratchet;
|
|
|
3 |
use Ratchet\Mock\ConnectionDecorator;
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* @covers Ratchet\AbstractConnectionDecorator
|
|
|
7 |
* @covers Ratchet\ConnectionInterface
|
|
|
8 |
*/
|
|
|
9 |
class AbstractConnectionDecoratorTest extends \PHPUnit_Framework_TestCase {
|
|
|
10 |
protected $mock;
|
|
|
11 |
protected $l1;
|
|
|
12 |
protected $l2;
|
|
|
13 |
|
|
|
14 |
public function setUp() {
|
|
|
15 |
$this->mock = $this->getMock('\Ratchet\ConnectionInterface');
|
|
|
16 |
$this->l1 = new ConnectionDecorator($this->mock);
|
|
|
17 |
$this->l2 = new ConnectionDecorator($this->l1);
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public function testGet() {
|
|
|
21 |
$var = 'hello';
|
|
|
22 |
$val = 'world';
|
|
|
23 |
|
|
|
24 |
$this->mock->$var = $val;
|
|
|
25 |
|
|
|
26 |
$this->assertEquals($val, $this->l1->$var);
|
|
|
27 |
$this->assertEquals($val, $this->l2->$var);
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public function testSet() {
|
|
|
31 |
$var = 'Chris';
|
|
|
32 |
$val = 'Boden';
|
|
|
33 |
|
|
|
34 |
$this->l1->$var = $val;
|
|
|
35 |
|
|
|
36 |
$this->assertEquals($val, $this->mock->$var);
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
public function testSetLevel2() {
|
|
|
40 |
$var = 'Try';
|
|
|
41 |
$val = 'Again';
|
|
|
42 |
|
|
|
43 |
$this->l2->$var = $val;
|
|
|
44 |
|
|
|
45 |
$this->assertEquals($val, $this->mock->$var);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public function testIsSetTrue() {
|
|
|
49 |
$var = 'PHP';
|
|
|
50 |
$val = 'Ratchet';
|
|
|
51 |
|
|
|
52 |
$this->mock->$var = $val;
|
|
|
53 |
|
|
|
54 |
$this->assertTrue(isset($this->l1->$var));
|
|
|
55 |
$this->assertTrue(isset($this->l2->$var));
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public function testIsSetFalse() {
|
|
|
59 |
$var = 'herp';
|
|
|
60 |
$val = 'derp';
|
|
|
61 |
|
|
|
62 |
$this->assertFalse(isset($this->l1->$var));
|
|
|
63 |
$this->assertFalse(isset($this->l2->$var));
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public function testUnset() {
|
|
|
67 |
$var = 'Flying';
|
|
|
68 |
$val = 'Monkey';
|
|
|
69 |
|
|
|
70 |
$this->mock->$var = $val;
|
|
|
71 |
unset($this->l1->$var);
|
|
|
72 |
|
|
|
73 |
$this->assertFalse(isset($this->mock->$var));
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public function testUnsetLevel2() {
|
|
|
77 |
$var = 'Flying';
|
|
|
78 |
$val = 'Monkey';
|
|
|
79 |
|
|
|
80 |
$this->mock->$var = $val;
|
|
|
81 |
unset($this->l2->$var);
|
|
|
82 |
|
|
|
83 |
$this->assertFalse(isset($this->mock->$var));
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
public function testGetConnection() {
|
|
|
87 |
$class = new \ReflectionClass('\\Ratchet\\AbstractConnectionDecorator');
|
|
|
88 |
$method = $class->getMethod('getConnection');
|
|
|
89 |
$method->setAccessible(true);
|
|
|
90 |
|
|
|
91 |
$conn = $method->invokeArgs($this->l1, array());
|
|
|
92 |
|
|
|
93 |
$this->assertSame($this->mock, $conn);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public function testGetConnectionLevel2() {
|
|
|
97 |
$class = new \ReflectionClass('\\Ratchet\\AbstractConnectionDecorator');
|
|
|
98 |
$method = $class->getMethod('getConnection');
|
|
|
99 |
$method->setAccessible(true);
|
|
|
100 |
|
|
|
101 |
$conn = $method->invokeArgs($this->l2, array());
|
|
|
102 |
|
|
|
103 |
$this->assertSame($this->l1, $conn);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public function testWrapperCanStoreSelfInDecorator() {
|
|
|
107 |
$this->mock->decorator = $this->l1;
|
|
|
108 |
|
|
|
109 |
$this->assertSame($this->l1, $this->l2->decorator);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public function testDecoratorRecursion() {
|
|
|
113 |
$this->mock->decorator = new \stdClass;
|
|
|
114 |
$this->mock->decorator->conn = $this->l1;
|
|
|
115 |
|
|
|
116 |
$this->assertSame($this->l1, $this->mock->decorator->conn);
|
|
|
117 |
$this->assertSame($this->l1, $this->l1->decorator->conn);
|
|
|
118 |
$this->assertSame($this->l1, $this->l2->decorator->conn);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
public function testDecoratorRecursionLevel2() {
|
|
|
122 |
$this->mock->decorator = new \stdClass;
|
|
|
123 |
$this->mock->decorator->conn = $this->l2;
|
|
|
124 |
|
|
|
125 |
$this->assertSame($this->l2, $this->mock->decorator->conn);
|
|
|
126 |
$this->assertSame($this->l2, $this->l1->decorator->conn);
|
|
|
127 |
$this->assertSame($this->l2, $this->l2->decorator->conn);
|
|
|
128 |
|
|
|
129 |
// just for fun
|
|
|
130 |
$this->assertSame($this->l2, $this->l2->decorator->conn->decorator->conn->decorator->conn);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
public function testWarningGettingNothing() {
|
|
|
134 |
$this->setExpectedException('PHPUnit_Framework_Error');
|
|
|
135 |
$var = $this->mock->nonExistant;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
public function testWarningGettingNothingLevel1() {
|
|
|
139 |
$this->setExpectedException('PHPUnit_Framework_Error');
|
|
|
140 |
$var = $this->l1->nonExistant;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public function testWarningGettingNothingLevel2() {
|
|
|
144 |
$this->setExpectedException('PHPUnit_Framework_Error');
|
|
|
145 |
$var = $this->l2->nonExistant;
|
|
|
146 |
}
|
|
|
147 |
}
|