75 changes: 51 additions & 24 deletions tests/unit/Wamp/ServerProtocolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use Ratchet\Mock\WampComponent as TestComponent;

/**
* @covers Ratchet\Wamp\ServerProtocol
* @covers Ratchet\Wamp\WampServerInterface
* @covers Ratchet\Wamp\WampConnection
* @covers \Ratchet\Wamp\ServerProtocol
* @covers \Ratchet\Wamp\WampServerInterface
* @covers \Ratchet\Wamp\WampConnection
*/
class ServerProtocolTest extends \PHPUnit_Framework_TestCase {
protected $_comp;
Expand All @@ -23,13 +23,13 @@ protected function newConn() {
}

public function invalidMessageProvider() {
return array(
array(0)
, array(3)
, array(4)
, array(8)
, array(9)
);
return [
[0]
, [3]
, [4]
, [8]
, [9]
];
}

/**
Expand All @@ -40,7 +40,7 @@ public function testInvalidMessages($type) {

$conn = $this->newConn();
$this->_comp->onOpen($conn);
$this->_comp->onMessage($conn, json_encode(array($type)));
$this->_comp->onMessage($conn, json_encode([$type]));
}

public function testWelcomeMessage() {
Expand Down Expand Up @@ -82,16 +82,16 @@ public function testUnSubscribe() {
}

public function callProvider() {
return array(
array(2, 'a', 'b')
, array(2, array('a', 'b'))
, array(1, 'one')
, array(3, 'one', 'two', 'three')
, array(3, array('un', 'deux', 'trois'))
, array(2, 'hi', array('hello', 'world'))
, array(2, array('hello', 'world'), 'hi')
, array(2, array('hello' => 'world', 'herp' => 'derp'))
);
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']]
];
}

/**
Expand All @@ -102,7 +102,7 @@ public function testCall() {
$paramNum = array_shift($args);

$uri = 'http://example.com/endpoint/' . rand(1, 100);
$id = uniqid();
$id = uniqid('', false);
$clientMessage = array_merge(array(2, $id, $uri), $args);

$conn = $this->newConn();
Expand Down Expand Up @@ -145,8 +145,8 @@ public function testPublishAndExcludeMe() {
public function testPublishAndEligible() {
$conn = $this->newConn();

$buddy = uniqid();
$friend = uniqid();
$buddy = uniqid('', false);
$friend = uniqid('', false);

$this->_comp->onOpen($conn);
$this->_comp->onMessage($conn, json_encode(array(7, 'topic', 'event', false, array($buddy, $friend))));
Expand Down Expand Up @@ -265,4 +265,31 @@ public function testValidJsonButInvalidProtocol($message) {
$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']));
}
}
13 changes: 5 additions & 8 deletions tests/unit/Wamp/TopicManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,18 @@ public function testConnIsRemovedFromTopicOnClose() {
}

public static function topicConnExpectationProvider() {
return array(
array(true, 'onClose', 0)
, array(true, 'onUnsubscribe', 0)
, array(false, 'onClose', 1)
, array(false, 'onUnsubscribe', 1)
);
return [
[ 'onClose', 0]
, ['onUnsubscribe', 0]
];
}

/**
* @dataProvider topicConnExpectationProvider
*/
public function testTopicRetentionFromLeavingConnections($autoDelete, $methodCall, $expectation) {
public function testTopicRetentionFromLeavingConnections($methodCall, $expectation) {
$topicName = 'checkTopic';
list($topic, $attribute) = $this->topicProvider($topicName);
$topic->autoDelete = $autoDelete;

$this->mngr->onSubscribe($this->conn, $topicName);
call_user_func_array(array($this->mngr, $methodCall), array($this->conn, $topicName));
Expand Down
103 changes: 0 additions & 103 deletions tests/unit/WebSocket/Version/Hixie76Test.php

This file was deleted.

67 changes: 0 additions & 67 deletions tests/unit/WebSocket/Version/HyBi10Test.php

This file was deleted.

543 changes: 0 additions & 543 deletions tests/unit/WebSocket/Version/RFC6455/FrameTest.php

This file was deleted.

170 changes: 0 additions & 170 deletions tests/unit/WebSocket/Version/RFC6455/HandshakeVerifierTest.php

This file was deleted.

63 changes: 0 additions & 63 deletions tests/unit/WebSocket/Version/RFC6455/MessageTest.php

This file was deleted.

151 changes: 0 additions & 151 deletions tests/unit/WebSocket/Version/RFC6455Test.php

This file was deleted.

91 changes: 0 additions & 91 deletions tests/unit/WebSocket/VersionManagerTest.php

This file was deleted.

51 changes: 0 additions & 51 deletions tests/unit/WebSocket/WsServerTest.php

This file was deleted.