aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/cboden/ratchet/tests/unit/Http
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/Http
parent286d643180672f20526f3dc3bd19d7b751e2fa97 (diff)
Initial Commit
Diffstat (limited to 'assets/php/vendor/cboden/ratchet/tests/unit/Http')
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Http/HttpRequestParserTest.php50
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Http/HttpServerTest.php64
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Http/OriginCheckTest.php46
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Http/RouterTest.php165
4 files changed, 325 insertions, 0 deletions
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Http/HttpRequestParserTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Http/HttpRequestParserTest.php
new file mode 100644
index 0000000..6af8402
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Http/HttpRequestParserTest.php
@@ -0,0 +1,50 @@
+<?php
+namespace Ratchet\Http;
+
+/**
+ * @covers Ratchet\Http\HttpRequestParser
+ */
+class HttpRequestParserTest extends \PHPUnit_Framework_TestCase {
+ protected $parser;
+
+ public function setUp() {
+ $this->parser = new HttpRequestParser;
+ }
+
+ public function headersProvider() {
+ return array(
+ array(false, "GET / HTTP/1.1\r\nHost: socketo.me\r\n")
+ , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n")
+ , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n1")
+ , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\nHixie✖")
+ , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\nHixie✖\r\n\r\n")
+ , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\nHixie\r\n")
+ );
+ }
+
+ /**
+ * @dataProvider headersProvider
+ */
+ public function testIsEom($expected, $message) {
+ $this->assertEquals($expected, $this->parser->isEom($message));
+ }
+
+ public function testBufferOverflowResponse() {
+ $conn = $this->getMock('\Ratchet\ConnectionInterface');
+
+ $this->parser->maxSize = 20;
+
+ $this->assertNull($this->parser->onMessage($conn, "GET / HTTP/1.1\r\n"));
+
+ $this->setExpectedException('OverflowException');
+
+ $this->parser->onMessage($conn, "Header-Is: Too Big");
+ }
+
+ public function testReturnTypeIsRequest() {
+ $conn = $this->getMock('\Ratchet\ConnectionInterface');
+ $return = $this->parser->onMessage($conn, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n");
+
+ $this->assertInstanceOf('\Psr\Http\Message\RequestInterface', $return);
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Http/HttpServerTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Http/HttpServerTest.php
new file mode 100644
index 0000000..7041d66
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Http/HttpServerTest.php
@@ -0,0 +1,64 @@
+<?php
+namespace Ratchet\Http;
+use Ratchet\AbstractMessageComponentTestCase;
+
+/**
+ * @covers Ratchet\Http\HttpServer
+ */
+class HttpServerTest extends AbstractMessageComponentTestCase {
+ public function setUp() {
+ parent::setUp();
+ $this->_conn->httpHeadersReceived = true;
+ }
+
+ public function getConnectionClassString() {
+ return '\Ratchet\ConnectionInterface';
+ }
+
+ public function getDecoratorClassString() {
+ return '\Ratchet\Http\HttpServer';
+ }
+
+ public function getComponentClassString() {
+ return '\Ratchet\Http\HttpServerInterface';
+ }
+
+ public function testOpen() {
+ $headers = "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n";
+
+ $this->_conn->httpHeadersReceived = false;
+ $this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection());
+ $this->_serv->onMessage($this->_conn, $headers);
+ }
+
+ public function testOnMessageAfterHeaders() {
+ $headers = "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n";
+ $this->_conn->httpHeadersReceived = false;
+ $this->_serv->onMessage($this->_conn, $headers);
+
+ $message = "Hello World!";
+ $this->_app->expects($this->once())->method('onMessage')->with($this->isExpectedConnection(), $message);
+ $this->_serv->onMessage($this->_conn, $message);
+ }
+
+ public function testBufferOverflow() {
+ $this->_conn->expects($this->once())->method('close');
+ $this->_conn->httpHeadersReceived = false;
+
+ $this->_serv->onMessage($this->_conn, str_repeat('a', 5000));
+ }
+
+ public function testCloseIfNotEstablished() {
+ $this->_conn->httpHeadersReceived = false;
+ $this->_conn->expects($this->once())->method('close');
+ $this->_serv->onError($this->_conn, new \Exception('Whoops!'));
+ }
+
+ public function testBufferHeaders() {
+ $this->_conn->httpHeadersReceived = false;
+ $this->_app->expects($this->never())->method('onOpen');
+ $this->_app->expects($this->never())->method('onMessage');
+
+ $this->_serv->onMessage($this->_conn, "GET / HTTP/1.1");
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Http/OriginCheckTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Http/OriginCheckTest.php
new file mode 100644
index 0000000..c1c4012
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Http/OriginCheckTest.php
@@ -0,0 +1,46 @@
+<?php
+namespace Ratchet\Http;
+use Ratchet\AbstractMessageComponentTestCase;
+
+/**
+ * @covers Ratchet\Http\OriginCheck
+ */
+class OriginCheckTest extends AbstractMessageComponentTestCase {
+ protected $_reqStub;
+
+ public function setUp() {
+ $this->_reqStub = $this->getMock('Psr\Http\Message\RequestInterface');
+ $this->_reqStub->expects($this->any())->method('getHeader')->will($this->returnValue(['localhost']));
+
+ parent::setUp();
+
+ $this->_serv->allowedOrigins[] = 'localhost';
+ }
+
+ protected function doOpen($conn) {
+ $this->_serv->onOpen($conn, $this->_reqStub);
+ }
+
+ public function getConnectionClassString() {
+ return '\Ratchet\ConnectionInterface';
+ }
+
+ public function getDecoratorClassString() {
+ return '\Ratchet\Http\OriginCheck';
+ }
+
+ public function getComponentClassString() {
+ return '\Ratchet\Http\HttpServerInterface';
+ }
+
+ public function testCloseOnNonMatchingOrigin() {
+ $this->_serv->allowedOrigins = ['socketo.me'];
+ $this->_conn->expects($this->once())->method('close');
+
+ $this->_serv->onOpen($this->_conn, $this->_reqStub);
+ }
+
+ public function testOnMessage() {
+ $this->passthroughMessageTest('Hello World!');
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Http/RouterTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Http/RouterTest.php
new file mode 100644
index 0000000..1ca4cbc
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Http/RouterTest.php
@@ -0,0 +1,165 @@
+<?php
+namespace Ratchet\Http;
+use Ratchet\WebSocket\WsServerInterface;
+use Symfony\Component\Routing\Exception\ResourceNotFoundException;
+use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
+use Symfony\Component\Routing\RequestContext;
+use Symfony\Component\Routing\RouteCollection;
+use Symfony\Component\Routing\Matcher\UrlMatcher;
+
+
+/**
+ * @covers Ratchet\Http\Router
+ */
+class RouterTest extends \PHPUnit_Framework_TestCase {
+ protected $_router;
+ protected $_matcher;
+ protected $_conn;
+ protected $_uri;
+ protected $_req;
+
+ public function setUp() {
+ $this->_conn = $this->getMock('\Ratchet\ConnectionInterface');
+ $this->_uri = $this->getMock('Psr\Http\Message\UriInterface');
+ $this->_req = $this->getMock('\Psr\Http\Message\RequestInterface');
+ $this->_req
+ ->expects($this->any())
+ ->method('getUri')
+ ->will($this->returnValue($this->_uri));
+ $this->_matcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
+ $this->_matcher
+ ->expects($this->any())
+ ->method('getContext')
+ ->will($this->returnValue($this->getMock('Symfony\Component\Routing\RequestContext')));
+ $this->_router = new Router($this->_matcher);
+
+ $this->_uri->expects($this->any())->method('getPath')->will($this->returnValue('ws://doesnt.matter/'));
+ $this->_uri->expects($this->any())->method('withQuery')->with($this->callback(function($val) {
+ $this->setResult($val);
+
+ return true;
+ }))->will($this->returnSelf());
+ $this->_uri->expects($this->any())->method('getQuery')->will($this->returnCallback([$this, 'getResult']));
+ $this->_req->expects($this->any())->method('withUri')->will($this->returnSelf());
+ }
+
+ public function testFourOhFour() {
+ $this->_conn->expects($this->once())->method('close');
+
+ $nope = new ResourceNotFoundException;
+ $this->_matcher->expects($this->any())->method('match')->will($this->throwException($nope));
+
+ $this->_router->onOpen($this->_conn, $this->_req);
+ }
+
+ public function testNullRequest() {
+ $this->setExpectedException('\UnexpectedValueException');
+ $this->_router->onOpen($this->_conn);
+ }
+
+ public function testControllerIsMessageComponentInterface() {
+ $this->setExpectedException('\UnexpectedValueException');
+ $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => new \StdClass)));
+ $this->_router->onOpen($this->_conn, $this->_req);
+ }
+
+ public function testControllerOnOpen() {
+ $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock();
+ $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => $controller)));
+ $this->_router->onOpen($this->_conn, $this->_req);
+
+ $expectedConn = new \PHPUnit_Framework_Constraint_IsInstanceOf('\Ratchet\ConnectionInterface');
+ $controller->expects($this->once())->method('onOpen')->with($expectedConn, $this->_req);
+
+ $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => $controller)));
+ $this->_router->onOpen($this->_conn, $this->_req);
+ }
+
+ public function testControllerOnMessageBubbles() {
+ $message = "The greatest trick the Devil ever pulled was convincing the world he didn't exist";
+ $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock();
+ $controller->expects($this->once())->method('onMessage')->with($this->_conn, $message);
+
+ $this->_conn->controller = $controller;
+
+ $this->_router->onMessage($this->_conn, $message);
+ }
+
+ public function testControllerOnCloseBubbles() {
+ $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock();
+ $controller->expects($this->once())->method('onClose')->with($this->_conn);
+
+ $this->_conn->controller = $controller;
+
+ $this->_router->onClose($this->_conn);
+ }
+
+ public function testControllerOnErrorBubbles() {
+ $e= new \Exception('One cannot be betrayed if one has no exceptions');
+ $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock();
+ $controller->expects($this->once())->method('onError')->with($this->_conn, $e);
+
+ $this->_conn->controller = $controller;
+
+ $this->_router->onError($this->_conn, $e);
+ }
+
+ public function testRouterGeneratesRouteParameters() {
+ /** @var $controller WsServerInterface */
+ $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock();
+ /** @var $matcher UrlMatcherInterface */
+ $this->_matcher->expects($this->any())->method('match')->will(
+ $this->returnValue(['_controller' => $controller, 'foo' => 'bar', 'baz' => 'qux'])
+ );
+ $conn = $this->getMock('Ratchet\Mock\Connection');
+
+ $router = new Router($this->_matcher);
+
+ $router->onOpen($conn, $this->_req);
+
+ $this->assertEquals('foo=bar&baz=qux', $this->_req->getUri()->getQuery());
+ }
+
+ public function testQueryParams() {
+ $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock();
+ $this->_matcher->expects($this->any())->method('match')->will(
+ $this->returnValue(['_controller' => $controller, 'foo' => 'bar', 'baz' => 'qux'])
+ );
+
+ $conn = $this->getMock('Ratchet\Mock\Connection');
+ $request = $this->getMock('Psr\Http\Message\RequestInterface');
+ $uri = new \GuzzleHttp\Psr7\Uri('ws://doesnt.matter/endpoint?hello=world&foo=nope');
+
+ $request->expects($this->any())->method('getUri')->will($this->returnCallback(function() use (&$uri) {
+ return $uri;
+ }));
+ $request->expects($this->any())->method('withUri')->with($this->callback(function($url) use (&$uri) {
+ $uri = $url;
+
+ return true;
+ }))->will($this->returnSelf());
+
+ $router = new Router($this->_matcher);
+ $router->onOpen($conn, $request);
+
+ $this->assertEquals('foo=nope&baz=qux&hello=world', $request->getUri()->getQuery());
+ $this->assertEquals('ws', $request->getUri()->getScheme());
+ $this->assertEquals('doesnt.matter', $request->getUri()->getHost());
+ }
+
+ public function testImpatientClientOverflow() {
+ $this->_conn->expects($this->once())->method('close');
+
+ $header = "GET /nope HTTP/1.1
+Upgrade: websocket
+Connection: upgrade
+Host: localhost
+Origin: http://localhost
+Sec-WebSocket-Version: 13\r\n\r\n";
+
+ $app = new HttpServer(new Router(new UrlMatcher(new RouteCollection, new RequestContext)));
+ $app->onOpen($this->_conn);
+ $app->onMessage($this->_conn, $header);
+ $app->onMessage($this->_conn, 'Silly body');
+ }
+}