Browse Source

Add tests

mscherer 7 years ago
parent
commit
78340f5fa6
2 changed files with 28 additions and 4 deletions
  1. 4 4
      src/Http/Response.php
  2. 24 0
      tests/TestCase/Http/ResponseTest.php

+ 4 - 4
src/Http/Response.php

@@ -1111,7 +1111,7 @@ class Response implements ResponseInterface
     {
         deprecationWarning(
             'Response::type() is deprecated. ' .
-            'Use getType(), setType() or withType() instead.'
+            'Use setTypeMap(), getType() or withType() instead.'
         );
 
         if ($contentType === null) {
@@ -1138,9 +1138,9 @@ class Response implements ResponseInterface
     }
 
     /**
-     * Sets a content type into the map.
+     * Sets a content type definition into the map.
      *
-     * E.g.: setType('xhtml' => ['application/xhtml+xml', 'application/xhtml', 'text/xhtml'])
+     * E.g.: setType('xhtml' => ['application/xhtml+xml', 'application/xhtml'])
      *
      * This is needed for RequestHandlerComponent and recognition of types.
      *
@@ -1148,7 +1148,7 @@ class Response implements ResponseInterface
      * @param string|array $mimeType Definition of the mime type.
      * @return void
      */
-    public function setType($type, $mimeType)
+    public function setTypeMap($type, $mimeType)
     {
         $this->_mimeTypes[$type] = $mimeType;
     }

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

@@ -266,6 +266,30 @@ class ResponseTest extends TestCase
     }
 
     /**
+     * @return void
+     */
+    public function testSetTypeMap()
+    {
+        $response = new Response();
+        $response->setTypeMap('ical', 'text/calendar');
+
+        $response = $response->withType('ical')->getType();
+        $this->assertEquals('text/calendar', $response);
+    }
+
+    /**
+     * @return void
+     */
+    public function testSetTypeMapAsArray()
+    {
+        $response = new Response();
+        $response->setTypeMap('ical', ['text/calendar']);
+
+        $response = $response->withType('ical')->getType();
+        $this->assertEquals('text/calendar', $response);
+    }
+
+    /**
      * Tests the withType method
      *
      * @return void