forked from rackspace/php-opencloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpResponseTest.php
More file actions
107 lines (103 loc) · 2.87 KB
/
HttpResponseTest.php
File metadata and controls
107 lines (103 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Unit Tests
*
* @copyright 2012-2013 Rackspace Hosting, Inc.
* See COPYING for licensing information
*
* @version 1.0.0
* @author Glen Campbell <glen.campbell@rackspace.com>
*/
require_once('http.inc');
define('TESTDATA',<<<ENDTESTDATA
Four score and seven years ago, our
fathers brought forth on this continent
a new nation, conceived in Liberty, and
dedicated to the proposition that all
men were created equal.
ENDTESTDATA
);
// stub for request
class MyStubRequest extends OpenCloud\CurlRequest {
public function info() {
parent::info();
return array('http_code'=>'200');
}
public function errno() {
parent::errno();
return 0;
}
public function error() {
parent::error();
return 'NOPE';
}
public function ReturnHeaders() {
return array(
"HTTP/1.1 200 OK\r\n",
"Content-Type: text/plain\r\n",
"X-Test-Header: Nothing\r\n"
);
}
}
class HttpResponseTest extends PHPUnit_Framework_TestCase
{
private
$response;
public function __construct() {
$request = new MyStubRequest('file:/dev/null');
$this->response = new OpenCloud\HttpResponse(
$request,
TESTDATA);
}
/**
* Tests
*/
public function test__construct() {
$req = new OpenCloud\CurlRequest('file:/dev/null');
$req->SetOption(CURLOPT_RETURNTRANSFER, TRUE);
$req->SetConnectTimeout(20);
$req->SetHttpTimeout(20);
$req->SetRetries(2);
$req->setheaders(array());
$req->SetHeader('X-Transfer-Name', 'Glen Campbell');
$req->Execute();
$req->info();
$req->errno();
$req->error();
$req->ReturnHeaders();
$req->_get_header_cb(curl_init('http://example.com'), 'X-Status: Blame');
$this->response = new OpenCloud\HttpResponse(
$req,
TESTDATA);
$this->assertGreaterThan(0, count($this->response->Headers()));
$this->assertEquals('', $req->close());
}
public function testHttpBody() {
$this->assertEquals('Four', substr($this->response->HttpBody(), 0, 4));
}
public function testHeaders() {
$harr = $this->response->Headers();
$this->assertEquals(3, sizeof($harr));
foreach($harr as $name => $value)
$this->assertEquals(
trim($value),
$value);
}
public function testHeader() {
$this->assertEquals(
'Nothing',
$this->response->Header('X-Test-Header'));
}
public function testinfo() {
$this->assertEquals(TRUE, is_array($this->response->info()));
}
public function testerrno() {
$this->assertEquals(0, $this->response->errno());
}
public function testerror() {
$this->assertEquals('NOPE', $this->response->error());
}
public function testHttpStatus() {
$this->assertEquals(200, $this->response->HttpStatus());
}
}