| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
namespace Ratchet\Wamp;
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
* @covers Ratchet\Wamp\WampConnection
|
|
|
6 |
*/
|
|
|
7 |
class WampConnectionTest extends \PHPUnit_Framework_TestCase {
|
|
|
8 |
protected $conn;
|
|
|
9 |
protected $mock;
|
|
|
10 |
|
|
|
11 |
public function setUp() {
|
|
|
12 |
$this->mock = $this->getMock('\\Ratchet\\ConnectionInterface');
|
|
|
13 |
$this->conn = new WampConnection($this->mock);
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
public function testCallResult() {
|
|
|
17 |
$callId = uniqid();
|
|
|
18 |
$data = array('hello' => 'world', 'herp' => 'derp');
|
|
|
19 |
|
|
|
20 |
$this->mock->expects($this->once())->method('send')->with(json_encode(array(3, $callId, $data)));
|
|
|
21 |
|
|
|
22 |
$this->conn->callResult($callId, $data);
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
public function testCallError() {
|
|
|
26 |
$callId = uniqid();
|
|
|
27 |
$uri = 'http://example.com/end/point';
|
|
|
28 |
|
|
|
29 |
$this->mock->expects($this->once())->method('send')->with(json_encode(array(4, $callId, $uri, '')));
|
|
|
30 |
|
|
|
31 |
$this->conn->callError($callId, $uri);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public function testCallErrorWithTopic() {
|
|
|
35 |
$callId = uniqid();
|
|
|
36 |
$uri = 'http://example.com/end/point';
|
|
|
37 |
|
|
|
38 |
$this->mock->expects($this->once())->method('send')->with(json_encode(array(4, $callId, $uri, '')));
|
|
|
39 |
|
|
|
40 |
$this->conn->callError($callId, new Topic($uri));
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public function testDetailedCallError() {
|
|
|
44 |
$callId = uniqid();
|
|
|
45 |
$uri = 'http://example.com/end/point';
|
|
|
46 |
$desc = 'beep boop beep';
|
|
|
47 |
$detail = 'Error: Too much awesome';
|
|
|
48 |
|
|
|
49 |
$this->mock->expects($this->once())->method('send')->with(json_encode(array(4, $callId, $uri, $desc, $detail)));
|
|
|
50 |
|
|
|
51 |
$this->conn->callError($callId, $uri, $desc, $detail);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
public function testPrefix() {
|
|
|
55 |
$shortOut = 'outgoing';
|
|
|
56 |
$longOut = 'http://example.com/outgoing';
|
|
|
57 |
|
|
|
58 |
$this->mock->expects($this->once())->method('send')->with(json_encode(array(1, $shortOut, $longOut)));
|
|
|
59 |
|
|
|
60 |
$this->conn->prefix($shortOut, $longOut);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public function testGetUriWhenNoCurieGiven() {
|
|
|
64 |
$uri = 'http://example.com/noshort';
|
|
|
65 |
|
|
|
66 |
$this->assertEquals($uri, $this->conn->getUri($uri));
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public function testClose() {
|
|
|
70 |
$mock = $this->getMock('\\Ratchet\\ConnectionInterface');
|
|
|
71 |
$conn = new WampConnection($mock);
|
|
|
72 |
|
|
|
73 |
$mock->expects($this->once())->method('close');
|
|
|
74 |
|
|
|
75 |
$conn->close();
|
|
|
76 |
}
|
|
|
77 |
}
|