Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

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