HttpRequestParserTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Ratchet\Http;
  3. /**
  4. * @covers Ratchet\Http\HttpRequestParser
  5. */
  6. class HttpRequestParserTest extends \PHPUnit_Framework_TestCase {
  7. protected $parser;
  8. public function setUp() {
  9. $this->parser = new HttpRequestParser;
  10. }
  11. public function headersProvider() {
  12. return array(
  13. array(false, "GET / HTTP/1.1\r\nHost: socketo.me\r\n")
  14. , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n")
  15. , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n1")
  16. , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\nHixie✖")
  17. , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\nHixie✖\r\n\r\n")
  18. , array(true, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\nHixie\r\n")
  19. );
  20. }
  21. /**
  22. * @dataProvider headersProvider
  23. */
  24. public function testIsEom($expected, $message) {
  25. $this->assertEquals($expected, $this->parser->isEom($message));
  26. }
  27. public function testBufferOverflowResponse() {
  28. $conn = $this->getMock('\Ratchet\ConnectionInterface');
  29. $this->parser->maxSize = 20;
  30. $this->assertNull($this->parser->onMessage($conn, "GET / HTTP/1.1\r\n"));
  31. $this->setExpectedException('OverflowException');
  32. $this->parser->onMessage($conn, "Header-Is: Too Big");
  33. }
  34. public function testReturnTypeIsRequest() {
  35. $conn = $this->getMock('\Ratchet\ConnectionInterface');
  36. $return = $this->parser->onMessage($conn, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n");
  37. $this->assertInstanceOf('\Psr\Http\Message\RequestInterface', $return);
  38. }
  39. }