From 9d2939e1e83c2c4521a73b7d7168d6ca394506fc Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 13 Jun 2012 22:51:42 -0400 Subject: [PATCH] [WebSocket] Cleanup Added a couple coverage unit tests CS --- src/Ratchet/WebSocket/Version/RFC6455/Frame.php | 10 +++++----- src/Ratchet/WebSocket/WsServer.php | 7 ------- .../Tests/WebSocket/HtpRequestParserTest.php | 3 --- .../Tests/WebSocket/VersionManagerTest.php | 16 +++++++++++++++- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Ratchet/WebSocket/Version/RFC6455/Frame.php b/src/Ratchet/WebSocket/Version/RFC6455/Frame.php index 21ad94d..126ad4c 100644 --- a/src/Ratchet/WebSocket/Version/RFC6455/Frame.php +++ b/src/Ratchet/WebSocket/Version/RFC6455/Frame.php @@ -3,11 +3,11 @@ namespace Ratchet\WebSocket\Version\RFC6455; use Ratchet\WebSocket\Version\FrameInterface; class Frame implements FrameInterface { - const OP_CONTINUE = 0; - const OP_TEXT = 1; - const OP_BINARY = 2; - const OP_CLOSE = 8; - const OP_PING = 9; + const OP_CONTINUE = 0; + const OP_TEXT = 1; + const OP_BINARY = 2; + const OP_CLOSE = 8; + const OP_PING = 9; const OP_PONG = 10; const CLOSE_NORMAL = 1000; diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 6ee3e7a..dc388d1 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -8,7 +8,6 @@ use Guzzle\Http\Message\Response; /** * The adapter to handle WebSocket requests/responses * This is a mediator between the Server and your application to handle real-time messaging through a web browser - * @todo Separate this class into a two classes: Component and a protocol handler * @link http://ca.php.net/manual/en/ref.http.php * @link http://dev.w3.org/html5/websockets/ */ @@ -73,12 +72,6 @@ class WsServer implements MessageComponentInterface { * {@inheritdoc} */ public function onOpen(ConnectionInterface $conn) { - //$wsConn = new WsConnection($conn); - - //$this->connections->attach($conn, $wsConn); - - //$this->reqParser->onOpen($wsConn); - $conn->WebSocket = new \StdClass; $conn->WebSocket->established = false; } diff --git a/tests/Ratchet/Tests/WebSocket/HtpRequestParserTest.php b/tests/Ratchet/Tests/WebSocket/HtpRequestParserTest.php index 91b4a2b..b3f1600 100644 --- a/tests/Ratchet/Tests/WebSocket/HtpRequestParserTest.php +++ b/tests/Ratchet/Tests/WebSocket/HtpRequestParserTest.php @@ -31,7 +31,6 @@ class HttpRequestParserTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($expected, $this->parser->isEom($message)); } - public function testBufferOverflowResponse() { $conn = new ConnectionStub; @@ -42,7 +41,5 @@ class HttpRequestParserTest extends \PHPUnit_Framework_TestCase { $this->setExpectedException('OverflowException'); $this->parser->onMessage($conn, "Header-Is: Too Big"); - - //$this->assertGreaterThan(400, $this->parser->onMessage($conn, "Header-Is: Too Big")->getStatusCode()); } } \ No newline at end of file diff --git a/tests/Ratchet/Tests/WebSocket/VersionManagerTest.php b/tests/Ratchet/Tests/WebSocket/VersionManagerTest.php index 85cde70..68fa336 100644 --- a/tests/Ratchet/Tests/WebSocket/VersionManagerTest.php +++ b/tests/Ratchet/Tests/WebSocket/VersionManagerTest.php @@ -44,8 +44,22 @@ class VersionManagerTest extends \PHPUnit_Framework_TestCase { $this->setExpectedException('InvalidArgumentException'); $this->vm->getVersion($req); + } - //$this->assertFalse($this->vm->getVersion($req)); + public function testYesIsVersionEnabled() { + $this->vm->enableVersion(new RFC6455); + + $this->assertTrue($this->vm->isVersionEnabled(new EntityEnclosingRequest('get', '/', array( + 'Host' => 'socketo.me' + , 'Sec-WebSocket-Version' => 13 + )))); + } + + public function testNoIsVersionEnabled() { + $this->assertFalse($this->vm->isVersionEnabled(new EntityEnclosingRequest('get', '/', array( + 'Host' => 'socketo.me' + , 'Sec-WebSocket-Version' => 9000 + )))); } public function testGetSupportedVersionString() {