Browse Source

Add getEncoding()

This gives a more consistent name with the rest of the PSR7 interface
methods.
Mark Story 10 years ago
parent
commit
aa90dcef42
2 changed files with 35 additions and 0 deletions
  1. 11 0
      src/Http/Client/Response.php
  2. 24 0
      tests/TestCase/Network/Http/ResponseTest.php

+ 11 - 0
src/Http/Client/Response.php

@@ -332,9 +332,20 @@ class Response extends Message implements ResponseInterface
      * Get the encoding if it was set.
      *
      * @return string|null
+     * @deprecated 3.3.0 Use getEncoding() instead.
      */
     public function encoding()
     {
+        return $this->getEncoding();
+    }
+
+    /**
+     * Get the encoding if it was set.
+     *
+     * @return string|null
+     */
+    public function getEncoding()
+    {
         $content = $this->getHeaderLine('content-type');
         if (!$content) {
             return null;

+ 24 - 0
tests/TestCase/Network/Http/ResponseTest.php

@@ -147,6 +147,16 @@ class ResponseTest extends TestCase
     }
 
     /**
+     * Test accessor for json
+     *
+     * @return void
+     */
+    public function testBodyJsonPsr7()
+    {
+        $this->markTestIncomplete();
+    }
+
+    /**
      * Test accessor for xml
      *
      * @return void
@@ -279,6 +289,16 @@ XML;
     }
 
     /**
+     * Test accessing cookies set through the PSR7 interface.
+     *
+     * @return void
+     */
+    public function testCookiesPsr7()
+    {
+        $this->markTestIncomplete();
+    }
+
+    /**
      * Test statusCode()
      *
      * @return void
@@ -291,6 +311,7 @@ XML;
         ];
         $response = new Response($headers, '');
         $this->assertEquals(404, $response->statusCode());
+        $this->assertEquals(404, $response->getStatusCode());
 
         $this->assertEquals(404, $response->code);
         $this->assertTrue(isset($response->code));
@@ -314,6 +335,7 @@ XML;
             'Content-Type: text/html'
         ];
         $response = new Response($headers, '');
+        $this->assertNull($response->getEncoding());
         $this->assertNull($response->encoding());
 
         $headers = [
@@ -321,6 +343,7 @@ XML;
             'Content-Type: text/html; charset="UTF-8"'
         ];
         $response = new Response($headers, '');
+        $this->assertEquals('UTF-8', $response->getEncoding());
         $this->assertEquals('UTF-8', $response->encoding());
 
         $headers = [
@@ -328,6 +351,7 @@ XML;
             "Content-Type: text/html; charset='ISO-8859-1'"
         ];
         $response = new Response($headers, '');
+        $this->assertEquals('ISO-8859-1', $response->getEncoding());
         $this->assertEquals('ISO-8859-1', $response->encoding());
     }