Browse Source

Fix Http\Client\Response::getStatusCode() should return int, but return string currently.

Koji Tanaka 9 years ago
parent
commit
6176a1e473
2 changed files with 7 additions and 7 deletions
  1. 1 1
      src/Http/Client/Response.php
  2. 6 6
      tests/TestCase/Network/Http/ResponseTest.php

+ 1 - 1
src/Http/Client/Response.php

@@ -195,7 +195,7 @@ class Response extends Message implements ResponseInterface
             if (substr($value, 0, 5) === 'HTTP/') {
                 preg_match('/HTTP\/([\d.]+) ([0-9]+)(.*)/i', $value, $matches);
                 $this->protocol = $matches[1];
-                $this->code = $matches[2];
+                $this->code = (int)$matches[2];
                 $this->reasonPhrase = trim($matches[3]);
                 continue;
             }

+ 6 - 6
tests/TestCase/Network/Http/ResponseTest.php

@@ -36,7 +36,7 @@ class ResponseTest extends TestCase
         $response = new Response($headers, 'winner!');
 
         $this->assertEquals('1.0', $response->getProtocolVersion());
-        $this->assertEquals(200, $response->getStatusCode());
+        $this->assertSame(200, $response->getStatusCode());
         $this->assertEquals('OK', $response->getReasonPhrase());
         $this->assertEquals(
             'text/html;charset="UTF-8"',
@@ -63,7 +63,7 @@ class ResponseTest extends TestCase
         ];
         $response = new Response($headers, 'ok');
 
-        $this->assertEquals(200, $response->statusCode());
+        $this->assertSame(200, $response->statusCode());
         $this->assertEquals('1.0', $response->version());
         $this->assertEquals(
             'text/html;charset="UTF-8"',
@@ -86,7 +86,7 @@ class ResponseTest extends TestCase
         $response = new Response($headers, 'ok');
 
         $this->assertEquals('1.0', $response->version());
-        $this->assertEquals(200, $response->statusCode());
+        $this->assertSame(200, $response->statusCode());
     }
 
     /**
@@ -342,10 +342,10 @@ XML;
             'Content-Type: text/html'
         ];
         $response = new Response($headers, '');
-        $this->assertEquals(404, $response->statusCode());
-        $this->assertEquals(404, $response->getStatusCode());
+        $this->assertSame(404, $response->statusCode());
+        $this->assertSame(404, $response->getStatusCode());
 
-        $this->assertEquals(404, $response->code);
+        $this->assertSame(404, $response->code);
         $this->assertTrue(isset($response->code));
     }