WampConnectionTest.php 2.3 KB

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