Browse Source

Fix incorrect triggering of callable strings

chinpei215 8 years ago
parent
commit
c68a773912
2 changed files with 18 additions and 1 deletions
  1. 1 1
      src/Http/Response.php
  2. 17 0
      tests/TestCase/Http/ResponseTest.php

+ 1 - 1
src/Http/Response.php

@@ -828,7 +828,7 @@ class Response implements ResponseInterface
         }
         }
 
 
         // Compatibility with closure/streaming responses
         // Compatibility with closure/streaming responses
-        if (is_callable($content)) {
+        if (!is_string($content) && is_callable($content)) {
             $this->stream = new CallbackStream($content);
             $this->stream = new CallbackStream($content);
         } else {
         } else {
             $this->_createStream();
             $this->_createStream();

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

@@ -522,6 +522,23 @@ class ResponseTest extends TestCase
     }
     }
 
 
     /**
     /**
+     * Tests that callable strings are not triggered
+     *
+     * @return void
+     */
+    public function testSendWithCallableStringBody()
+    {
+        $response = $this->getMockBuilder('Cake\Http\Response')
+            ->setMethods(['_sendHeader'])
+            ->getMock();
+        $response->body('phpversion');
+
+        ob_start();
+        $response->send();
+        $this->assertEquals('phpversion', ob_get_clean());
+    }
+
+    /**
      * Tests the disableCache method
      * Tests the disableCache method
      *
      *
      * @return void
      * @return void