[WAMP] Topic testing
Fixed bugs failing on Travis More unit test coverage
This commit is contained in:
parent
8d0cf5ffb2
commit
4078a360a8
@ -49,7 +49,7 @@ class TopicManager implements WsServerInterface, WampServerInterface {
|
|||||||
public function onUnsubscribe(ConnectionInterface $conn, $topic) {
|
public function onUnsubscribe(ConnectionInterface $conn, $topic) {
|
||||||
$topicObj = $this->getTopic($topic);
|
$topicObj = $this->getTopic($topic);
|
||||||
|
|
||||||
if ($conn->WAMP->topics->contains($topicobj)) {
|
if ($conn->WAMP->topics->contains($topicObj)) {
|
||||||
$conn->WAMP->topics->remove($topicObj);
|
$conn->WAMP->topics->remove($topicObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,11 @@ use Ratchet\MessageComponentInterface;
|
|||||||
use Ratchet\WebSocket\WsServerInterface;
|
use Ratchet\WebSocket\WsServerInterface;
|
||||||
use Ratchet\ConnectionInterface;
|
use Ratchet\ConnectionInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class just makes it 1 step easier to use Topic objects in WAMP
|
||||||
|
* If you're looking at the source code, look in the __construct of this
|
||||||
|
* class and use that to make your application instead of using this
|
||||||
|
*/
|
||||||
class WampServer implements MessageComponentInterface, WsServerInterface {
|
class WampServer implements MessageComponentInterface, WsServerInterface {
|
||||||
/**
|
/**
|
||||||
* @var ServerProtocol
|
* @var ServerProtocol
|
||||||
|
@ -15,6 +15,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->mock = $this->getMock('\\Ratchet\\Wamp\\WampServerInterface');
|
$this->mock = $this->getMock('\\Ratchet\\Wamp\\WampServerInterface');
|
||||||
$this->mngr = new TopicManager($this->mock);
|
$this->mngr = new TopicManager($this->mock);
|
||||||
|
|
||||||
|
$this->conn->WAMP = new \StdClass;
|
||||||
$this->mngr->onOpen($this->conn);
|
$this->mngr->onOpen($this->conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@ class WampServerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->mock = $this->getMock('\\Ratchet\\Wamp\\WampServerInterface');
|
$this->mock = $this->getMock('\\Ratchet\\Wamp\\WampServerInterface');
|
||||||
$this->serv = new WampServer($this->mock);
|
$this->serv = new WampServer($this->mock);
|
||||||
$this->conn = $this->getMock('\\Ratchet\\ConnectionInterface');
|
$this->conn = $this->getMock('\\Ratchet\\ConnectionInterface');
|
||||||
|
|
||||||
|
$this->serv->onOpen($this->conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isWampConn() {
|
public function isWampConn() {
|
||||||
@ -22,6 +24,36 @@ class WampServerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
public function testOpen() {
|
public function testOpen() {
|
||||||
$this->mock->expects($this->once())->method('onOpen')->with($this->isWampConn());
|
$this->mock->expects($this->once())->method('onOpen')->with($this->isWampConn());
|
||||||
$this->serv->onOpen($this->conn);
|
$this->serv->onOpen($this->getMock('\\Ratchet\\ConnectionInterface'));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function testOnClose() {
|
||||||
|
$this->mock->expects($this->once())->method('onClose')->with($this->isWampConn());
|
||||||
|
$this->serv->onClose($this->conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOnError() {
|
||||||
|
$e = new \Exception('hurr hurr');
|
||||||
|
$this->mock->expects($this->once())->method('onError')->with($this->isWampConn(), $e);
|
||||||
|
$this->serv->onError($this->conn, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOnMessageToEvent() {
|
||||||
|
$published = 'Client published this message';
|
||||||
|
|
||||||
|
$this->mock->expects($this->once())->method('onPublish')->with(
|
||||||
|
$this->isWampConn()
|
||||||
|
, new \PHPUnit_Framework_Constraint_IsInstanceOf('\\Ratchet\\Wamp\\Topic')
|
||||||
|
, $published
|
||||||
|
, array()
|
||||||
|
, array()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->serv->onMessage($this->conn, json_encode(array(7, 'topic', $published)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSubProtocols() {
|
||||||
|
// todo: could expand on this
|
||||||
|
$this->assertInternalType('array', $this->serv->getSubProtocols());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user