aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/cboden/ratchet/tests/unit/Wamp
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-10 21:50:16 +0200
committermarvin-borner@live.com2018-04-10 21:54:48 +0200
commitfc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch)
treeb0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/cboden/ratchet/tests/unit/Wamp
parent286d643180672f20526f3dc3bd19d7b751e2fa97 (diff)
Initial Commit
Diffstat (limited to 'assets/php/vendor/cboden/ratchet/tests/unit/Wamp')
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Wamp/ServerProtocolTest.php295
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Wamp/TopicManagerTest.php226
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Wamp/TopicTest.php164
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Wamp/WampConnectionTest.php77
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Wamp/WampServerTest.php49
5 files changed, 811 insertions, 0 deletions
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/ServerProtocolTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/ServerProtocolTest.php
new file mode 100644
index 0000000..8ff68c2
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/ServerProtocolTest.php
@@ -0,0 +1,295 @@
+<?php
+namespace Ratchet\Wamp;
+use Ratchet\Mock\Connection;
+use Ratchet\Mock\WampComponent as TestComponent;
+
+/**
+ * @covers \Ratchet\Wamp\ServerProtocol
+ * @covers \Ratchet\Wamp\WampServerInterface
+ * @covers \Ratchet\Wamp\WampConnection
+ */
+class ServerProtocolTest extends \PHPUnit_Framework_TestCase {
+ protected $_comp;
+
+ protected $_app;
+
+ public function setUp() {
+ $this->_app = new TestComponent;
+ $this->_comp = new ServerProtocol($this->_app);
+ }
+
+ protected function newConn() {
+ return new Connection;
+ }
+
+ public function invalidMessageProvider() {
+ return [
+ [0]
+ , [3]
+ , [4]
+ , [8]
+ , [9]
+ ];
+ }
+
+ /**
+ * @dataProvider invalidMessageProvider
+ */
+ public function testInvalidMessages($type) {
+ $this->setExpectedException('\Ratchet\Wamp\Exception');
+
+ $conn = $this->newConn();
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, json_encode([$type]));
+ }
+
+ public function testWelcomeMessage() {
+ $conn = $this->newConn();
+
+ $this->_comp->onOpen($conn);
+
+ $message = $conn->last['send'];
+ $json = json_decode($message);
+
+ $this->assertEquals(4, count($json));
+ $this->assertEquals(0, $json[0]);
+ $this->assertTrue(is_string($json[1]));
+ $this->assertEquals(1, $json[2]);
+ }
+
+ public function testSubscribe() {
+ $uri = 'http://example.com';
+ $clientMessage = array(5, $uri);
+
+ $conn = $this->newConn();
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, json_encode($clientMessage));
+
+ $this->assertEquals($uri, $this->_app->last['onSubscribe'][1]);
+ }
+
+ public function testUnSubscribe() {
+ $uri = 'http://example.com/endpoint';
+ $clientMessage = array(6, $uri);
+
+ $conn = $this->newConn();
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, json_encode($clientMessage));
+
+ $this->assertEquals($uri, $this->_app->last['onUnSubscribe'][1]);
+ }
+
+ public function callProvider() {
+ return [
+ [2, 'a', 'b']
+ , [2, ['a', 'b']]
+ , [1, 'one']
+ , [3, 'one', 'two', 'three']
+ , [3, ['un', 'deux', 'trois']]
+ , [2, 'hi', ['hello', 'world']]
+ , [2, ['hello', 'world'], 'hi']
+ , [2, ['hello' => 'world', 'herp' => 'derp']]
+ ];
+ }
+
+ /**
+ * @dataProvider callProvider
+ */
+ public function testCall() {
+ $args = func_get_args();
+ $paramNum = array_shift($args);
+
+ $uri = 'http://example.com/endpoint/' . rand(1, 100);
+ $id = uniqid('', false);
+ $clientMessage = array_merge(array(2, $id, $uri), $args);
+
+ $conn = $this->newConn();
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, json_encode($clientMessage));
+
+ $this->assertEquals($id, $this->_app->last['onCall'][1]);
+ $this->assertEquals($uri, $this->_app->last['onCall'][2]);
+
+ $this->assertEquals($paramNum, count($this->_app->last['onCall'][3]));
+ }
+
+ public function testPublish() {
+ $conn = $this->newConn();
+
+ $topic = 'pubsubhubbub';
+ $event = 'Here I am, publishing data';
+
+ $clientMessage = array(7, $topic, $event);
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, json_encode($clientMessage));
+
+ $this->assertEquals($topic, $this->_app->last['onPublish'][1]);
+ $this->assertEquals($event, $this->_app->last['onPublish'][2]);
+ $this->assertEquals(array(), $this->_app->last['onPublish'][3]);
+ $this->assertEquals(array(), $this->_app->last['onPublish'][4]);
+ }
+
+ public function testPublishAndExcludeMe() {
+ $conn = $this->newConn();
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, json_encode(array(7, 'topic', 'event', true)));
+
+ $this->assertEquals($conn->WAMP->sessionId, $this->_app->last['onPublish'][3][0]);
+ }
+
+ public function testPublishAndEligible() {
+ $conn = $this->newConn();
+
+ $buddy = uniqid('', false);
+ $friend = uniqid('', false);
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, json_encode(array(7, 'topic', 'event', false, array($buddy, $friend))));
+
+ $this->assertEquals(array(), $this->_app->last['onPublish'][3]);
+ $this->assertEquals(2, count($this->_app->last['onPublish'][4]));
+ }
+
+ public function eventProvider() {
+ return array(
+ array('http://example.com', array('one', 'two'))
+ , array('curie', array(array('hello' => 'world', 'herp' => 'derp')))
+ );
+ }
+
+ /**
+ * @dataProvider eventProvider
+ */
+ public function testEvent($topic, $payload) {
+ $conn = new WampConnection($this->newConn());
+ $conn->event($topic, $payload);
+
+ $eventString = $conn->last['send'];
+
+ $this->assertSame(array(8, $topic, $payload), json_decode($eventString, true));
+ }
+
+ public function testOnClosePropagation() {
+ $conn = new Connection;
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onClose($conn);
+
+ $class = new \ReflectionClass('\\Ratchet\\Wamp\\WampConnection');
+ $method = $class->getMethod('getConnection');
+ $method->setAccessible(true);
+
+ $check = $method->invokeArgs($this->_app->last['onClose'][0], array());
+
+ $this->assertSame($conn, $check);
+ }
+
+ public function testOnErrorPropagation() {
+ $conn = new Connection;
+
+ $e = new \Exception('Nope');
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onError($conn, $e);
+
+ $class = new \ReflectionClass('\\Ratchet\\Wamp\\WampConnection');
+ $method = $class->getMethod('getConnection');
+ $method->setAccessible(true);
+
+ $check = $method->invokeArgs($this->_app->last['onError'][0], array());
+
+ $this->assertSame($conn, $check);
+ $this->assertSame($e, $this->_app->last['onError'][1]);
+ }
+
+ public function testPrefix() {
+ $conn = new WampConnection($this->newConn());
+ $this->_comp->onOpen($conn);
+
+ $prefix = 'incoming';
+ $fullURI = "http://example.com/$prefix";
+ $method = 'call';
+
+ $this->_comp->onMessage($conn, json_encode(array(1, $prefix, $fullURI)));
+
+ $this->assertEquals($fullURI, $conn->WAMP->prefixes[$prefix]);
+ $this->assertEquals("$fullURI#$method", $conn->getUri("$prefix:$method"));
+ }
+
+ public function testMessageMustBeJson() {
+ $this->setExpectedException('\\Ratchet\\Wamp\\JsonException');
+
+ $conn = new Connection;
+
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, 'Hello World!');
+ }
+
+ public function testGetSubProtocolsReturnsArray() {
+ $this->assertTrue(is_array($this->_comp->getSubProtocols()));
+ }
+
+ public function testGetSubProtocolsGetFromApp() {
+ $this->_app->protocols = array('hello', 'world');
+
+ $this->assertGreaterThanOrEqual(3, count($this->_comp->getSubProtocols()));
+ }
+
+ public function testWampOnMessageApp() {
+ $app = $this->getMock('\\Ratchet\\Wamp\\WampServerInterface');
+ $wamp = new ServerProtocol($app);
+
+ $this->assertContains('wamp', $wamp->getSubProtocols());
+ }
+
+ public function badFormatProvider() {
+ return array(
+ array(json_encode(true))
+ , array('{"valid":"json", "invalid": "message"}')
+ , array('{"0": "fail", "hello": "world"}')
+ );
+ }
+
+ /**
+ * @dataProvider badFormatProvider
+ */
+ public function testValidJsonButInvalidProtocol($message) {
+ $this->setExpectedException('\Ratchet\Wamp\Exception');
+
+ $conn = $this->newConn();
+ $this->_comp->onOpen($conn);
+ $this->_comp->onMessage($conn, $message);
+ }
+
+ public function testBadClientInputFromNonStringTopic() {
+ $this->setExpectedException('\Ratchet\Wamp\Exception');
+
+ $conn = new WampConnection($this->newConn());
+ $this->_comp->onOpen($conn);
+
+ $this->_comp->onMessage($conn, json_encode([5, ['hells', 'nope']]));
+ }
+
+ public function testBadPrefixWithNonStringTopic() {
+ $this->setExpectedException('\Ratchet\Wamp\Exception');
+
+ $conn = new WampConnection($this->newConn());
+ $this->_comp->onOpen($conn);
+
+ $this->_comp->onMessage($conn, json_encode([1, ['hells', 'nope'], ['bad', 'input']]));
+ }
+
+ public function testBadPublishWithNonStringTopic() {
+ $this->setExpectedException('\Ratchet\Wamp\Exception');
+
+ $conn = new WampConnection($this->newConn());
+ $this->_comp->onOpen($conn);
+
+ $this->_comp->onMessage($conn, json_encode([7, ['bad', 'input'], 'Hider']));
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/TopicManagerTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/TopicManagerTest.php
new file mode 100644
index 0000000..b21b6bc
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/TopicManagerTest.php
@@ -0,0 +1,226 @@
+<?php
+namespace Ratchet\Wamp;
+
+/**
+ * @covers Ratchet\Wamp\TopicManager
+ */
+class TopicManagerTest extends \PHPUnit_Framework_TestCase {
+ private $mock;
+
+ /**
+ * @var \Ratchet\Wamp\TopicManager
+ */
+ private $mngr;
+
+ /**
+ * @var \Ratchet\ConnectionInterface
+ */
+ private $conn;
+
+ public function setUp() {
+ $this->conn = $this->getMock('\Ratchet\ConnectionInterface');
+ $this->mock = $this->getMock('\Ratchet\Wamp\WampServerInterface');
+ $this->mngr = new TopicManager($this->mock);
+
+ $this->conn->WAMP = new \StdClass;
+ $this->mngr->onOpen($this->conn);
+ }
+
+ public function testGetTopicReturnsTopicObject() {
+ $class = new \ReflectionClass('Ratchet\Wamp\TopicManager');
+ $method = $class->getMethod('getTopic');
+ $method->setAccessible(true);
+
+ $topic = $method->invokeArgs($this->mngr, array('The Topic'));
+
+ $this->assertInstanceOf('Ratchet\Wamp\Topic', $topic);
+ }
+
+ public function testGetTopicCreatesTopicWithSameName() {
+ $name = 'The Topic';
+
+ $class = new \ReflectionClass('Ratchet\Wamp\TopicManager');
+ $method = $class->getMethod('getTopic');
+ $method->setAccessible(true);
+
+ $topic = $method->invokeArgs($this->mngr, array($name));
+
+ $this->assertEquals($name, $topic->getId());
+ }
+
+ public function testGetTopicReturnsSameObject() {
+ $class = new \ReflectionClass('Ratchet\Wamp\TopicManager');
+ $method = $class->getMethod('getTopic');
+ $method->setAccessible(true);
+
+ $topic = $method->invokeArgs($this->mngr, array('No copy'));
+ $again = $method->invokeArgs($this->mngr, array('No copy'));
+
+ $this->assertSame($topic, $again);
+ }
+
+ public function testOnOpen() {
+ $this->mock->expects($this->once())->method('onOpen');
+ $this->mngr->onOpen($this->conn);
+ }
+
+ public function testOnCall() {
+ $id = uniqid();
+
+ $this->mock->expects($this->once())->method('onCall')->with(
+ $this->conn
+ , $id
+ , $this->isInstanceOf('Ratchet\Wamp\Topic')
+ , array()
+ );
+
+ $this->mngr->onCall($this->conn, $id, 'new topic', array());
+ }
+
+ public function testOnSubscribeCreatesTopicObject() {
+ $this->mock->expects($this->once())->method('onSubscribe')->with(
+ $this->conn, $this->isInstanceOf('Ratchet\Wamp\Topic')
+ );
+
+ $this->mngr->onSubscribe($this->conn, 'new topic');
+ }
+
+ public function testTopicIsInConnectionOnSubscribe() {
+ $name = 'New Topic';
+
+ $class = new \ReflectionClass('Ratchet\Wamp\TopicManager');
+ $method = $class->getMethod('getTopic');
+ $method->setAccessible(true);
+
+ $topic = $method->invokeArgs($this->mngr, array($name));
+
+ $this->mngr->onSubscribe($this->conn, $name);
+
+ $this->assertTrue($this->conn->WAMP->subscriptions->contains($topic));
+ }
+
+ public function testDoubleSubscriptionFiresOnce() {
+ $this->mock->expects($this->exactly(1))->method('onSubscribe');
+
+ $this->mngr->onSubscribe($this->conn, 'same topic');
+ $this->mngr->onSubscribe($this->conn, 'same topic');
+ }
+
+ public function testUnsubscribeEvent() {
+ $name = 'in and out';
+ $this->mock->expects($this->once())->method('onUnsubscribe')->with(
+ $this->conn, $this->isInstanceOf('Ratchet\Wamp\Topic')
+ );
+
+ $this->mngr->onSubscribe($this->conn, $name);
+ $this->mngr->onUnsubscribe($this->conn, $name);
+ }
+
+ public function testUnsubscribeFiresOnce() {
+ $name = 'getting sleepy';
+ $this->mock->expects($this->exactly(1))->method('onUnsubscribe');
+
+ $this->mngr->onSubscribe($this->conn, $name);
+ $this->mngr->onUnsubscribe($this->conn, $name);
+ $this->mngr->onUnsubscribe($this->conn, $name);
+ }
+
+ public function testUnsubscribeRemovesTopicFromConnection() {
+ $name = 'Bye Bye Topic';
+
+ $class = new \ReflectionClass('Ratchet\Wamp\TopicManager');
+ $method = $class->getMethod('getTopic');
+ $method->setAccessible(true);
+
+ $topic = $method->invokeArgs($this->mngr, array($name));
+
+ $this->mngr->onSubscribe($this->conn, $name);
+ $this->mngr->onUnsubscribe($this->conn, $name);
+
+ $this->assertFalse($this->conn->WAMP->subscriptions->contains($topic));
+ }
+
+ public function testOnPublishBubbles() {
+ $msg = 'Cover all the code!';
+
+ $this->mock->expects($this->once())->method('onPublish')->with(
+ $this->conn
+ , $this->isInstanceOf('Ratchet\Wamp\Topic')
+ , $msg
+ , $this->isType('array')
+ , $this->isType('array')
+ );
+
+ $this->mngr->onPublish($this->conn, 'topic coverage', $msg, array(), array());
+ }
+
+ public function testOnCloseBubbles() {
+ $this->mock->expects($this->once())->method('onClose')->with($this->conn);
+ $this->mngr->onClose($this->conn);
+ }
+
+ protected function topicProvider($name) {
+ $class = new \ReflectionClass('Ratchet\Wamp\TopicManager');
+ $method = $class->getMethod('getTopic');
+ $method->setAccessible(true);
+
+ $attribute = $class->getProperty('topicLookup');
+ $attribute->setAccessible(true);
+
+ $topic = $method->invokeArgs($this->mngr, array($name));
+
+ return array($topic, $attribute);
+ }
+
+ public function testConnIsRemovedFromTopicOnClose() {
+ $name = 'State Testing';
+ list($topic, $attribute) = $this->topicProvider($name);
+
+ $this->assertCount(1, $attribute->getValue($this->mngr));
+
+ $this->mngr->onSubscribe($this->conn, $name);
+ $this->mngr->onClose($this->conn);
+
+ $this->assertFalse($topic->has($this->conn));
+ }
+
+ public static function topicConnExpectationProvider() {
+ return [
+ [ 'onClose', 0]
+ , ['onUnsubscribe', 0]
+ ];
+ }
+
+ /**
+ * @dataProvider topicConnExpectationProvider
+ */
+ public function testTopicRetentionFromLeavingConnections($methodCall, $expectation) {
+ $topicName = 'checkTopic';
+ list($topic, $attribute) = $this->topicProvider($topicName);
+
+ $this->mngr->onSubscribe($this->conn, $topicName);
+ call_user_func_array(array($this->mngr, $methodCall), array($this->conn, $topicName));
+
+ $this->assertCount($expectation, $attribute->getValue($this->mngr));
+ }
+
+ public function testOnErrorBubbles() {
+ $e = new \Exception('All work and no play makes Chris a dull boy');
+ $this->mock->expects($this->once())->method('onError')->with($this->conn, $e);
+
+ $this->mngr->onError($this->conn, $e);
+ }
+
+ public function testGetSubProtocolsReturnsArray() {
+ $this->assertInternalType('array', $this->mngr->getSubProtocols());
+ }
+
+ public function testGetSubProtocolsBubbles() {
+ $subs = array('hello', 'world');
+ $app = $this->getMock('Ratchet\Wamp\Stub\WsWampServerInterface');
+ $app->expects($this->once())->method('getSubProtocols')->will($this->returnValue($subs));
+ $mngr = new TopicManager($app);
+
+ $this->assertEquals($subs, $mngr->getSubProtocols());
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/TopicTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/TopicTest.php
new file mode 100644
index 0000000..b8685b7
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/TopicTest.php
@@ -0,0 +1,164 @@
+<?php
+namespace Ratchet\Wamp;
+
+/**
+ * @covers Ratchet\Wamp\Topic
+ */
+class TopicTest extends \PHPUnit_Framework_TestCase {
+ public function testGetId() {
+ $id = uniqid();
+ $topic = new Topic($id);
+
+ $this->assertEquals($id, $topic->getId());
+ }
+
+ public function testAddAndCount() {
+ $topic = new Topic('merp');
+
+ $topic->add($this->newConn());
+ $topic->add($this->newConn());
+ $topic->add($this->newConn());
+
+ $this->assertEquals(3, count($topic));
+ }
+
+ public function testRemove() {
+ $topic = new Topic('boop');
+ $tracked = $this->newConn();
+
+ $topic->add($this->newConn());
+ $topic->add($tracked);
+ $topic->add($this->newConn());
+
+ $topic->remove($tracked);
+
+ $this->assertEquals(2, count($topic));
+ }
+
+ public function testBroadcast() {
+ $msg = 'Hello World!';
+ $name = 'Batman';
+ $protocol = json_encode(array(8, $name, $msg));
+
+ $first = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface')));
+ $second = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface')));
+
+ $first->expects($this->once())
+ ->method('send')
+ ->with($this->equalTo($protocol));
+
+ $second->expects($this->once())
+ ->method('send')
+ ->with($this->equalTo($protocol));
+
+ $topic = new Topic($name);
+ $topic->add($first);
+ $topic->add($second);
+
+ $topic->broadcast($msg);
+ }
+
+ public function testBroadcastWithExclude() {
+ $msg = 'Hello odd numbers';
+ $name = 'Excluding';
+ $protocol = json_encode(array(8, $name, $msg));
+
+ $first = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface')));
+ $second = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface')));
+ $third = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface')));
+
+ $first->expects($this->once())
+ ->method('send')
+ ->with($this->equalTo($protocol));
+
+ $second->expects($this->never())->method('send');
+
+ $third->expects($this->once())
+ ->method('send')
+ ->with($this->equalTo($protocol));
+
+ $topic = new Topic($name);
+ $topic->add($first);
+ $topic->add($second);
+ $topic->add($third);
+
+ $topic->broadcast($msg, array($second->WAMP->sessionId));
+ }
+
+ public function testBroadcastWithEligible() {
+ $msg = 'Hello white list';
+ $name = 'Eligible';
+ $protocol = json_encode(array(8, $name, $msg));
+
+ $first = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface')));
+ $second = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface')));
+ $third = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface')));
+
+ $first->expects($this->once())
+ ->method('send')
+ ->with($this->equalTo($protocol));
+
+ $second->expects($this->never())->method('send');
+
+ $third->expects($this->once())
+ ->method('send')
+ ->with($this->equalTo($protocol));
+
+ $topic = new Topic($name);
+ $topic->add($first);
+ $topic->add($second);
+ $topic->add($third);
+
+ $topic->broadcast($msg, array(), array($first->WAMP->sessionId, $third->WAMP->sessionId));
+ }
+
+ public function testIterator() {
+ $first = $this->newConn();
+ $second = $this->newConn();
+ $third = $this->newConn();
+
+ $topic = new Topic('Joker');
+ $topic->add($first)->add($second)->add($third);
+
+ $check = array($first, $second, $third);
+
+ foreach ($topic as $mock) {
+ $this->assertNotSame(false, array_search($mock, $check));
+ }
+ }
+
+ public function testToString() {
+ $name = 'Bane';
+ $topic = new Topic($name);
+
+ $this->assertEquals($name, (string)$topic);
+ }
+
+ public function testDoesHave() {
+ $conn = $this->newConn();
+ $topic = new Topic('Two Face');
+ $topic->add($conn);
+
+ $this->assertTrue($topic->has($conn));
+ }
+
+ public function testDoesNotHave() {
+ $conn = $this->newConn();
+ $topic = new Topic('Alfred');
+
+ $this->assertFalse($topic->has($conn));
+ }
+
+ public function testDoesNotHaveAfterRemove() {
+ $conn = $this->newConn();
+ $topic = new Topic('Ras');
+
+ $topic->add($conn)->remove($conn);
+
+ $this->assertFalse($topic->has($conn));
+ }
+
+ protected function newConn() {
+ return new WampConnection($this->getMock('\\Ratchet\\ConnectionInterface'));
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/WampConnectionTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/WampConnectionTest.php
new file mode 100644
index 0000000..adf59d5
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/WampConnectionTest.php
@@ -0,0 +1,77 @@
+<?php
+namespace Ratchet\Wamp;
+
+/**
+ * @covers Ratchet\Wamp\WampConnection
+ */
+class WampConnectionTest extends \PHPUnit_Framework_TestCase {
+ protected $conn;
+ protected $mock;
+
+ public function setUp() {
+ $this->mock = $this->getMock('\\Ratchet\\ConnectionInterface');
+ $this->conn = new WampConnection($this->mock);
+ }
+
+ public function testCallResult() {
+ $callId = uniqid();
+ $data = array('hello' => 'world', 'herp' => 'derp');
+
+ $this->mock->expects($this->once())->method('send')->with(json_encode(array(3, $callId, $data)));
+
+ $this->conn->callResult($callId, $data);
+ }
+
+ public function testCallError() {
+ $callId = uniqid();
+ $uri = 'http://example.com/end/point';
+
+ $this->mock->expects($this->once())->method('send')->with(json_encode(array(4, $callId, $uri, '')));
+
+ $this->conn->callError($callId, $uri);
+ }
+
+ public function testCallErrorWithTopic() {
+ $callId = uniqid();
+ $uri = 'http://example.com/end/point';
+
+ $this->mock->expects($this->once())->method('send')->with(json_encode(array(4, $callId, $uri, '')));
+
+ $this->conn->callError($callId, new Topic($uri));
+ }
+
+ public function testDetailedCallError() {
+ $callId = uniqid();
+ $uri = 'http://example.com/end/point';
+ $desc = 'beep boop beep';
+ $detail = 'Error: Too much awesome';
+
+ $this->mock->expects($this->once())->method('send')->with(json_encode(array(4, $callId, $uri, $desc, $detail)));
+
+ $this->conn->callError($callId, $uri, $desc, $detail);
+ }
+
+ public function testPrefix() {
+ $shortOut = 'outgoing';
+ $longOut = 'http://example.com/outgoing';
+
+ $this->mock->expects($this->once())->method('send')->with(json_encode(array(1, $shortOut, $longOut)));
+
+ $this->conn->prefix($shortOut, $longOut);
+ }
+
+ public function testGetUriWhenNoCurieGiven() {
+ $uri = 'http://example.com/noshort';
+
+ $this->assertEquals($uri, $this->conn->getUri($uri));
+ }
+
+ public function testClose() {
+ $mock = $this->getMock('\\Ratchet\\ConnectionInterface');
+ $conn = new WampConnection($mock);
+
+ $mock->expects($this->once())->method('close');
+
+ $conn->close();
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/WampServerTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/WampServerTest.php
new file mode 100644
index 0000000..626b1ce
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Wamp/WampServerTest.php
@@ -0,0 +1,49 @@
+<?php
+namespace Ratchet\Wamp;
+use Ratchet\AbstractMessageComponentTestCase;
+
+/**
+ * @covers Ratchet\Wamp\WampServer
+ */
+class WampServerTest extends AbstractMessageComponentTestCase {
+ public function getConnectionClassString() {
+ return '\Ratchet\Wamp\WampConnection';
+ }
+
+ public function getDecoratorClassString() {
+ return 'Ratchet\Wamp\WampServer';
+ }
+
+ public function getComponentClassString() {
+ return '\Ratchet\Wamp\WampServerInterface';
+ }
+
+ public function testOnMessageToEvent() {
+ $published = 'Client published this message';
+
+ $this->_app->expects($this->once())->method('onPublish')->with(
+ $this->isExpectedConnection()
+ , 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());
+ }
+
+ public function testConnectionClosesOnInvalidJson() {
+ $this->_conn->expects($this->once())->method('close');
+ $this->_serv->onMessage($this->_conn, 'invalid json');
+ }
+
+ public function testConnectionClosesOnProtocolError() {
+ $this->_conn->expects($this->once())->method('close');
+ $this->_serv->onMessage($this->_conn, json_encode(array('valid' => 'json', 'invalid' => 'protocol')));
+ }
+}