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