[WAMP] Topic testing

Fixed bugs failing on Travis
More unit test coverage
This commit is contained in:
Chris Boden 2012-07-19 00:14:36 -04:00
parent 8d0cf5ffb2
commit 4078a360a8
4 changed files with 41 additions and 3 deletions

View File

@ -49,7 +49,7 @@ class TopicManager implements WsServerInterface, WampServerInterface {
public function onUnsubscribe(ConnectionInterface $conn, $topic) {
$topicObj = $this->getTopic($topic);
if ($conn->WAMP->topics->contains($topicobj)) {
if ($conn->WAMP->topics->contains($topicObj)) {
$conn->WAMP->topics->remove($topicObj);
}

View File

@ -4,6 +4,11 @@ use Ratchet\MessageComponentInterface;
use Ratchet\WebSocket\WsServerInterface;
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 {
/**
* @var ServerProtocol

View File

@ -15,6 +15,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase {
$this->mock = $this->getMock('\\Ratchet\\Wamp\\WampServerInterface');
$this->mngr = new TopicManager($this->mock);
$this->conn->WAMP = new \StdClass;
$this->mngr->onOpen($this->conn);
}

View File

@ -14,6 +14,8 @@ class WampServerTest extends \PHPUnit_Framework_TestCase {
$this->mock = $this->getMock('\\Ratchet\\Wamp\\WampServerInterface');
$this->serv = new WampServer($this->mock);
$this->conn = $this->getMock('\\Ratchet\\ConnectionInterface');
$this->serv->onOpen($this->conn);
}
public function isWampConn() {
@ -22,6 +24,36 @@ class WampServerTest extends \PHPUnit_Framework_TestCase {
public function testOpen() {
$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());
}
}