Skip to content

Commit be27628

Browse files
authored
Merge pull request #1 from dantleech/fix-curl-infos
Fix curl infos
2 parents 41f5321 + 054dc5a commit be27628

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

src/VCR/Response.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public function toArray()
6565
array(
6666
'status' => $this->status,
6767
'headers' => $this->getHeaders(),
68-
'body' => $body
68+
'body' => $body,
69+
'curl_info' => $this->curlInfo,
6970
)
7071
);
7172
}
@@ -94,7 +95,8 @@ public static function fromArray(array $response)
9495
return new static(
9596
isset($response['status']) ? $response['status'] : 200,
9697
isset($response['headers']) ? $response['headers'] : array(),
97-
$body
98+
$body,
99+
isset($response['curl_info']) ? $response['curl_info'] : array()
98100
);
99101
}
100102

src/VCR/Util/CurlHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static function getCurlOptionFromResponse(Response $response, $option = 0
112112
$info = mb_strlen(HttpUtil::formatAsStatusWithHeadersString($response), 'ISO-8859-1');
113113
break;
114114
default:
115-
$info = $response->getCurlInfo($option);
115+
$info = $response->getCurlInfo(self::$curlInfoList[$option]);
116116
break;
117117
}
118118

tests/VCR/ResponseTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ public function testGetCurlInfo()
120120
$this->assertEquals($curlOptions, $response->getCurlInfo());
121121
}
122122

123+
public function testRestoreCurlInfoFromArray()
124+
{
125+
$expectedCurlOptions = array('option' => 'value');
126+
$response = new Response(200, array(), null, $expectedCurlOptions);
127+
$restoredResponse = Response::fromArray($response->toArray());
128+
129+
$this->assertEquals($expectedCurlOptions, $response->getCurlInfo());
130+
}
131+
123132
public function testToArray()
124133
{
125134
$expectedArray = array(
@@ -131,7 +140,10 @@ public function testToArray()
131140
'headers' => array(
132141
'host' => 'example.com'
133142
),
134-
'body' => 'Test response'
143+
'body' => 'Test response',
144+
'curl_info' => array(
145+
'content_type' => 'text/html'
146+
)
135147
);
136148

137149
$response = Response::fromArray($expectedArray);

tests/fixtures/unittest_curl_test

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,33 @@
1111
headers:
1212
Location: 'http://www.google.com/'
1313
Content-Type: 'text/html; charset=UTF-8'
14-
Date: 'Mon, 13 May 2013 08:15:58 GMT'
15-
Expires: 'Wed, 12 Jun 2013 08:15:58 GMT'
14+
Date: 'Wed, 18 Oct 2017 18:59:08 GMT'
15+
Expires: 'Wed, 17 Nov 2017 18:59:08 GMT'
1616
Cache-Control: 'public, max-age=2592000'
1717
Server: gws
1818
Content-Length: '219'
1919
X-XSS-Protection: '1; mode=block'
2020
X-Frame-Options: SAMEORIGIN
2121
body: "This is a curl test dummy."
22+
curl_info:
23+
url: 'http://google.com/'
24+
content_type: 'text/html; charset=UTF-8'
25+
http_code: 301
26+
header_size: 249
27+
request_size: 49
28+
filetime: -1
29+
ssl_verify_result: 0
30+
redirect_count: 0
31+
total_time: 0.194497
32+
namelookup_time: 0.132455
33+
connect_time: 0.164555
34+
pretransfer_time: 0.164586
35+
size_upload: !!float 0
36+
size_download: !!float 268
37+
speed_download: !!float 1377
38+
speed_upload: !!float 0
39+
download_content_length: !!float 268
40+
upload_content_length: !!float -1
41+
starttransfer_time: 0.194476
42+
certinfo: { }
43+
primary_port: 80

0 commit comments

Comments
 (0)