Skip to content

Commit 256036f

Browse files
authored
Merge pull request php-vcr#220 from renatomefi/pr/192
CurlHook now returns integer HTTP status codes
2 parents 3535845 + 9c0a50a commit 256036f

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/VCR/Util/CurlHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static function getCurlOptionFromResponse(Response $response, $option = 0
103103
}
104104
break;
105105
case CURLINFO_HTTP_CODE:
106-
$info = $response->getStatusCode();
106+
$info = (int)$response->getStatusCode();
107107
break;
108108
case CURLINFO_SIZE_DOWNLOAD:
109109
$info = $response->getHeader('Content-Length');

tests/VCR/LibraryHooks/CurlHookTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,31 @@ public function testShouldReturnCurlInfoStatusCode()
176176
$infoHttpCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
177177
curl_close($curlHandle);
178178

179-
$this->assertEquals(200, $infoHttpCode, 'HTTP status not set.');
179+
$this->assertSame(200, $infoHttpCode, 'HTTP status not set.');
180+
180181
$this->curlHook->disable();
181182
}
182183

184+
/**
185+
* @see https://github.com/php-vcr/php-vcr/issues/136
186+
*/
187+
public function testShouldReturnCurlInfoStatusCodeAsInteger()
188+
{
189+
$stringStatusCode = "200";
190+
$integerStatusCode = 200;
191+
$this->curlHook->enable($this->getTestCallback($stringStatusCode));
192+
193+
$curlHandle = curl_init('http://example.com');
194+
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
195+
curl_exec($curlHandle);
196+
$infoHttpCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
197+
curl_close($curlHandle);
198+
199+
$this->assertSame($integerStatusCode, $infoHttpCode, 'HTTP status not set.');
200+
201+
$this->curlHook->disable();
202+
}
203+
183204
public function testShouldReturnCurlInfoAll()
184205
{
185206
$this->curlHook->enable($this->getTestCallback());
@@ -340,11 +361,11 @@ function (Request $request) use ($testClass) {
340361
/**
341362
* @return \callable
342363
*/
343-
protected function getTestCallback()
364+
protected function getTestCallback($statusCode = 200)
344365
{
345366
$testClass = $this;
346-
return function () use ($testClass) {
347-
return new Response(200, array(), $testClass->expected);
367+
return function () use ($statusCode, $testClass) {
368+
return new Response($statusCode, array(), $testClass->expected);
348369
};
349370
}
350371
}

0 commit comments

Comments
 (0)