WampServerTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Ratchet\Wamp;
  3. use Ratchet\AbstractMessageComponentTestCase;
  4. /**
  5. * @covers Ratchet\Wamp\WampServer
  6. */
  7. class WampServerTest extends AbstractMessageComponentTestCase {
  8. public function getConnectionClassString() {
  9. return '\Ratchet\Wamp\WampConnection';
  10. }
  11. public function getDecoratorClassString() {
  12. return 'Ratchet\Wamp\WampServer';
  13. }
  14. public function getComponentClassString() {
  15. return '\Ratchet\Wamp\WampServerInterface';
  16. }
  17. public function testOnMessageToEvent() {
  18. $published = 'Client published this message';
  19. $this->_app->expects($this->once())->method('onPublish')->with(
  20. $this->isExpectedConnection()
  21. , new \PHPUnit_Framework_Constraint_IsInstanceOf('\Ratchet\Wamp\Topic')
  22. , $published
  23. , array()
  24. , array()
  25. );
  26. $this->_serv->onMessage($this->_conn, json_encode(array(7, 'topic', $published)));
  27. }
  28. public function testGetSubProtocols() {
  29. // todo: could expand on this
  30. $this->assertInternalType('array', $this->_serv->getSubProtocols());
  31. }
  32. public function testConnectionClosesOnInvalidJson() {
  33. $this->_conn->expects($this->once())->method('close');
  34. $this->_serv->onMessage($this->_conn, 'invalid json');
  35. }
  36. public function testConnectionClosesOnProtocolError() {
  37. $this->_conn->expects($this->once())->method('close');
  38. $this->_serv->onMessage($this->_conn, json_encode(array('valid' => 'json', 'invalid' => 'protocol')));
  39. }
  40. }