HttpServerTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Ratchet\Http;
  3. use Ratchet\AbstractMessageComponentTestCase;
  4. /**
  5. * @covers Ratchet\Http\HttpServer
  6. */
  7. class HttpServerTest extends AbstractMessageComponentTestCase {
  8. public function setUp() {
  9. parent::setUp();
  10. $this->_conn->httpHeadersReceived = true;
  11. }
  12. public function getConnectionClassString() {
  13. return '\Ratchet\ConnectionInterface';
  14. }
  15. public function getDecoratorClassString() {
  16. return '\Ratchet\Http\HttpServer';
  17. }
  18. public function getComponentClassString() {
  19. return '\Ratchet\Http\HttpServerInterface';
  20. }
  21. public function testOpen() {
  22. $headers = "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n";
  23. $this->_conn->httpHeadersReceived = false;
  24. $this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection());
  25. $this->_serv->onMessage($this->_conn, $headers);
  26. }
  27. public function testOnMessageAfterHeaders() {
  28. $headers = "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n";
  29. $this->_conn->httpHeadersReceived = false;
  30. $this->_serv->onMessage($this->_conn, $headers);
  31. $message = "Hello World!";
  32. $this->_app->expects($this->once())->method('onMessage')->with($this->isExpectedConnection(), $message);
  33. $this->_serv->onMessage($this->_conn, $message);
  34. }
  35. public function testBufferOverflow() {
  36. $this->_conn->expects($this->once())->method('close');
  37. $this->_conn->httpHeadersReceived = false;
  38. $this->_serv->onMessage($this->_conn, str_repeat('a', 5000));
  39. }
  40. public function testCloseIfNotEstablished() {
  41. $this->_conn->httpHeadersReceived = false;
  42. $this->_conn->expects($this->once())->method('close');
  43. $this->_serv->onError($this->_conn, new \Exception('Whoops!'));
  44. }
  45. public function testBufferHeaders() {
  46. $this->_conn->httpHeadersReceived = false;
  47. $this->_app->expects($this->never())->method('onOpen');
  48. $this->_app->expects($this->never())->method('onMessage');
  49. $this->_serv->onMessage($this->_conn, "GET / HTTP/1.1");
  50. }
  51. }