[Tests] Bring up unit testing coverage
Coverage on Http and Session Set version to 0.3-beta Cleaned up a couple API doc things Removed Origin code from RFC, will be moved to Http
This commit is contained in:
parent
8df459548f
commit
344818d0f5
@ -5,7 +5,7 @@ namespace Ratchet;
|
|||||||
* The version of Ratchet being used
|
* The version of Ratchet being used
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const VERSION = 'Ratchet/0.2.5';
|
const VERSION = 'Ratchet/0.3-beta';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A proxy object representing a connection to the application
|
* A proxy object representing a connection to the application
|
||||||
|
@ -29,14 +29,14 @@ class HttpServer implements MessageComponentInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @{inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function onOpen(ConnectionInterface $conn) {
|
public function onOpen(ConnectionInterface $conn) {
|
||||||
$conn->httpHeadersReceived = false;
|
$conn->httpHeadersReceived = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @{inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function onMessage(ConnectionInterface $from, $msg) {
|
public function onMessage(ConnectionInterface $from, $msg) {
|
||||||
if (true !== $from->httpHeadersReceived) {
|
if (true !== $from->httpHeadersReceived) {
|
||||||
@ -57,7 +57,7 @@ class HttpServer implements MessageComponentInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @{inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function onClose(ConnectionInterface $conn) {
|
public function onClose(ConnectionInterface $conn) {
|
||||||
if ($conn->httpHeadersReceived) {
|
if ($conn->httpHeadersReceived) {
|
||||||
@ -66,7 +66,7 @@ class HttpServer implements MessageComponentInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @{inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function onError(ConnectionInterface $conn, \Exception $e) {
|
public function onError(ConnectionInterface $conn, \Exception $e) {
|
||||||
if ($conn->httpHeadersReceived) {
|
if ($conn->httpHeadersReceived) {
|
||||||
|
@ -42,7 +42,7 @@ class SessionProvider implements MessageComponentInterface, WsServerInterface {
|
|||||||
* @param \SessionHandlerInterface $handler
|
* @param \SessionHandlerInterface $handler
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @param \Ratchet\Session\Serialize\HandlerInterface $serializer
|
* @param \Ratchet\Session\Serialize\HandlerInterface $serializer
|
||||||
* @throws \RuntimeExcpetion
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function __construct(MessageComponentInterface $app, \SessionHandlerInterface $handler, array $options = array(), HandlerInterface $serializer = null) {
|
public function __construct(MessageComponentInterface $app, \SessionHandlerInterface $handler, array $options = array(), HandlerInterface $serializer = null) {
|
||||||
$this->_app = $app;
|
$this->_app = $app;
|
||||||
|
@ -113,22 +113,6 @@ class HandshakeVerifier {
|
|||||||
return (16 === strlen(base64_decode((string)$val)));
|
return (16 === strlen(base64_decode((string)$val)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify Origin matches RFC6454 IF it is set
|
|
||||||
* Origin is an optional field
|
|
||||||
* @param string|null
|
|
||||||
* @return bool
|
|
||||||
* @todo Implement verification functionality - see section 4.2.1.7
|
|
||||||
*/
|
|
||||||
public function verifyOrigin($val) {
|
|
||||||
if (null === $val) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// logic here
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify the version passed matches this RFC
|
* Verify the version passed matches this RFC
|
||||||
* @param string|int MUST equal 13|"13"
|
* @param string|int MUST equal 13|"13"
|
||||||
|
@ -216,7 +216,6 @@ class WsServer implements HttpServerInterface {
|
|||||||
* Close a connection with an HTTP response
|
* Close a connection with an HTTP response
|
||||||
* @param \Ratchet\ConnectionInterface $conn
|
* @param \Ratchet\ConnectionInterface $conn
|
||||||
* @param int $code HTTP status code
|
* @param int $code HTTP status code
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
protected function close(ConnectionInterface $conn, $code = 400) {
|
protected function close(ConnectionInterface $conn, $code = 400) {
|
||||||
$response = new Response($code, array(
|
$response = new Response($code, array(
|
||||||
|
@ -31,7 +31,7 @@ class HttpRequestParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testBufferOverflowResponse() {
|
public function testBufferOverflowResponse() {
|
||||||
$conn = $this->getMock('\\Ratchet\\ConnectionInterface');
|
$conn = $this->getMock('\Ratchet\ConnectionInterface');
|
||||||
|
|
||||||
$this->parser->maxSize = 20;
|
$this->parser->maxSize = 20;
|
||||||
|
|
||||||
@ -41,4 +41,11 @@ class HttpRequestParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
$this->parser->onMessage($conn, "Header-Is: Too Big");
|
$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('\Guzzle\Http\Message\RequestInterface', $return);
|
||||||
|
}
|
||||||
}
|
}
|
@ -30,4 +30,35 @@ class HttpServerTest extends AbstractMessageComponentTestCase {
|
|||||||
$this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection());
|
$this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection());
|
||||||
$this->_serv->onMessage($this->_conn, $headers);
|
$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");
|
||||||
|
}
|
||||||
}
|
}
|
@ -22,6 +22,10 @@ class SessionProviderTest extends AbstractMessageComponentTestCase {
|
|||||||
$this->_serv = new SessionProvider($this->_app, new NullSessionHandler);
|
$this->_serv = new SessionProvider($this->_app, new NullSessionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown() {
|
||||||
|
ini_set('session.serialize_handler', 'php');
|
||||||
|
}
|
||||||
|
|
||||||
public function getConnectionClassString() {
|
public function getConnectionClassString() {
|
||||||
return '\Ratchet\ConnectionInterface';
|
return '\Ratchet\ConnectionInterface';
|
||||||
}
|
}
|
||||||
@ -89,9 +93,9 @@ class SessionProviderTest extends AbstractMessageComponentTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function newConn() {
|
protected function newConn() {
|
||||||
$conn = $this->getMock('Ratchet\\ConnectionInterface');
|
$conn = $this->getMock('Ratchet\ConnectionInterface');
|
||||||
|
|
||||||
$headers = $this->getMock('Guzzle\\Http\\Message\\Request', array('getCookie'), array('POST', '/', array()));
|
$headers = $this->getMock('Guzzle\Http\Message\Request', array('getCookie'), array('POST', '/', array()));
|
||||||
$headers->expects($this->once())->method('getCookie', array(ini_get('session.name')))->will($this->returnValue(null));
|
$headers->expects($this->once())->method('getCookie', array(ini_get('session.name')))->will($this->returnValue(null));
|
||||||
|
|
||||||
$conn->WebSocket = new \StdClass;
|
$conn->WebSocket = new \StdClass;
|
||||||
@ -100,6 +104,12 @@ class SessionProviderTest extends AbstractMessageComponentTestCase {
|
|||||||
return $conn;
|
return $conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOnMessageDecorator() {
|
||||||
|
$message = "Database calls are usually blocking :(";
|
||||||
|
$this->_app->expects($this->once())->method('onMessage')->with($this->isExpectedConnection(), $message);
|
||||||
|
$this->_serv->onMessage($this->_conn, $message);
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetSubProtocolsReturnsArray() {
|
public function testGetSubProtocolsReturnsArray() {
|
||||||
$mock = $this->getMock('Ratchet\\MessageComponentInterface');
|
$mock = $this->getMock('Ratchet\\MessageComponentInterface');
|
||||||
$comp = new SessionProvider($mock, new NullSessionHandler);
|
$comp = new SessionProvider($mock, new NullSessionHandler);
|
||||||
@ -114,4 +124,10 @@ class SessionProviderTest extends AbstractMessageComponentTestCase {
|
|||||||
|
|
||||||
$this->assertGreaterThanOrEqual(2, count($comp->getSubProtocols()));
|
$this->assertGreaterThanOrEqual(2, count($comp->getSubProtocols()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRejectInvalidSeralizers() {
|
||||||
|
ini_set('session.serialize_handler', 'wddx');
|
||||||
|
$this->setExpectedException('\RuntimeException');
|
||||||
|
new SessionProvider($this->getMock('\Ratchet\MessageComponentInterface'), $this->getMock('\SessionHandlerInterface'));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user