diff --git a/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455/FrameTest.php b/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455/FrameTest.php index 90ab37d..c870d65 100644 --- a/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455/FrameTest.php +++ b/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455/FrameTest.php @@ -20,6 +20,17 @@ class FrameTest extends \PHPUnit_Framework_TestCase { } protected static function convert($in) { + if (strlen($in) > 8) { + $out = ''; + + while (strlen($in) > 8) { + $out .= static::convert(substr($in, 0, 8)); + $in = substr($in, 8); + } + + return $out; + } + return pack('C', bindec($in)); } @@ -37,6 +48,31 @@ class FrameTest extends \PHPUnit_Framework_TestCase { ); } + public static function underflowProvider() { + return array( + array('isFinal', '') + , array('getOpcode', '') + , array('isMasked', '10000001') + , array('getPayloadLength', '10000001') + , array('getPayloadLength', '1000000111111110') + , array('getMaskingKey', '1000000110000111') + , array('getPayload', '100000011000000100011100101010101001100111110100') + ); + } + + /** + * @dataProvider underflowProvider + */ + public function testUnderflowExceptionFromAllTheMethodsMimickingBuffering($method, $bin) { + $this->setExpectedException('\UnderflowException'); + + if (!empty($bin)) { + $this->_frame->addBuffer(static::convert($bin)); + } + + call_user_func(array($this->_frame, $method)); + } + /** * A data provider for testing the first byte of a WebSocket frame * @param bool Given, is the byte indicate this is the final frame @@ -53,12 +89,6 @@ class FrameTest extends \PHPUnit_Framework_TestCase { ); } - public function testUnderflowExceptionFromAllTheMethodsMimickingBuffering() { - return $this->markTestIncomplete(); - - $this->expectException('\UnderflowException'); - } - /** * @dataProvider firstByteProvider */ diff --git a/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455Test.php b/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455Test.php index 3be4b74..f32f59f 100644 --- a/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455Test.php +++ b/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455Test.php @@ -2,6 +2,7 @@ namespace Ratchet\Tests\Application\WebSocket\Version; use Ratchet\Application\WebSocket\Version\RFC6455; use Ratchet\Application\WebSocket\Version\RFC6455\Frame; +use Guzzle\Http\Message\RequestFactory; /** * @covers Ratchet\Application\WebSocket\Version\RFC6455 @@ -103,32 +104,25 @@ class RFC6455Test extends \PHPUnit_Framework_TestCase { public static function headerHandshakeProvider() { return array( array(false, "GET /test HTTP/1.0\r\n" . static::getAndSpliceHeader()) + , array(true, static::$good_rest . "\r\n" . static::getAndSpliceHeader()) + , array(false, "POST / HTTP:/1.1\r\n" . static::getAndSpliceHeader()) + , array(false, static::$good_rest . "\r\n" . static::getAndSpliceHeader('Upgrade', 'useless')) + , array(false, "GET /ಠ_ಠ HTTP/1.1\r\n" . static::getAndSpliceHeader()) + , array(true, static::$good_rest . "\r\n" . static::getAndSpliceHeader('Connection', 'Herp, Upgrade, Derp')) ); } -/* RFC example of a good header - GET /chat HTTP/1.1 - Host: server.example.com - Upgrade: websocket - Connection: Upgrade - Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== - Origin: http://example.com - Sec-WebSocket-Protocol: chat, superchat - Sec-WebSocket-Version: 13 -*/ - /** * @dataProvider headerHandshakeProvider - * @todo Can't finish this test until I rewrite headers */ public function testVariousHeadersToCheckHandshakeTolerance($pass, $header) { - return $this->markTestIncomplete(); + $request = RequestFactory::fromMessage($header); if ($pass) { - $this->assertTrue(is_array($this->_version->handshake($header))); + $this->assertTrue(is_array($this->_version->handshake($request))); } else { $this->setExpectedException('InvalidArgumentException'); - $this->_version->handshake($header); + $this->_version->handshake($request); } } } \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index cb1e591..d8416df 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -7,4 +7,5 @@ $app = new SplClassLoader('Ratchet', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lib'); $app->register(); - $app = new SplClassLoader('Guzzle', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'guzzle' . DIRECTORY_SEPARATOR . 'src'); \ No newline at end of file + $app = new SplClassLoader('Guzzle', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'guzzle' . DIRECTORY_SEPARATOR . 'src'); + $app->register(); \ No newline at end of file