| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
use Guzzle\Http\Message\Request;
|
|
|
3 |
|
|
|
4 |
class GuzzleTest extends \PHPUnit_Framework_TestCase {
|
|
|
5 |
protected $_request;
|
|
|
6 |
|
|
|
7 |
protected $_headers = array(
|
|
|
8 |
'Upgrade' => 'websocket'
|
|
|
9 |
, 'Connection' => 'Upgrade'
|
|
|
10 |
, 'Host' => 'localhost:8080'
|
|
|
11 |
, 'Origin' => 'chrome://newtab'
|
|
|
12 |
, 'Sec-WebSocket-Protocol' => 'one, two, three'
|
|
|
13 |
, 'Sec-WebSocket-Key' => '9bnXNp3ae6FbFFRtPdiPXA=='
|
|
|
14 |
, 'Sec-WebSocket-Version' => '13'
|
|
|
15 |
);
|
|
|
16 |
|
|
|
17 |
public function setUp() {
|
|
|
18 |
$this->_request = new Request('GET', 'http://localhost', $this->_headers);
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
public function testGetHeaderString() {
|
|
|
22 |
$this->assertEquals('Upgrade', (string)$this->_request->getHeader('connection'));
|
|
|
23 |
$this->assertEquals('9bnXNp3ae6FbFFRtPdiPXA==', (string)$this->_request->getHeader('Sec-Websocket-Key'));
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public function testGetHeaderInteger() {
|
|
|
27 |
$this->assertSame('13', (string)$this->_request->getHeader('Sec-Websocket-Version'));
|
|
|
28 |
$this->assertSame(13, (int)(string)$this->_request->getHeader('Sec-WebSocket-Version'));
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
public function testGetHeaderObject() {
|
|
|
32 |
$this->assertInstanceOf('Guzzle\Http\Message\Header', $this->_request->getHeader('Origin'));
|
|
|
33 |
$this->assertNull($this->_request->getHeader('Non-existant-header'));
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public function testHeaderObjectNormalizeValues() {
|
|
|
37 |
$expected = 1 + substr_count($this->_headers['Sec-WebSocket-Protocol'], ',');
|
|
|
38 |
$protocols = $this->_request->getHeader('Sec-WebSocket-Protocol')->normalize();
|
|
|
39 |
$count = 0;
|
|
|
40 |
|
|
|
41 |
foreach ($protocols as $protocol) {
|
|
|
42 |
$count++;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
$this->assertEquals($expected, $count);
|
|
|
46 |
$this->assertEquals($expected, count($protocols));
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public function testRequestFactoryCreateSignature() {
|
|
|
50 |
$ref = new \ReflectionMethod('Guzzle\Http\Message\RequestFactory', 'create');
|
|
|
51 |
$this->assertEquals(2, $ref->getNumberOfRequiredParameters());
|
|
|
52 |
}
|
|
|
53 |
}
|