Skip to content

Commit

Permalink
Fix incorrect triggering of callable strings
Browse files Browse the repository at this point in the history
  • Loading branch information
chinpei215 committed Dec 4, 2017
1 parent 3bf426d commit c68a773
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Response.php
Expand Up @@ -828,7 +828,7 @@ public function body($content = null)
}

// Compatibility with closure/streaming responses
if (is_callable($content)) {
if (!is_string($content) && is_callable($content)) {
$this->stream = new CallbackStream($content);
} else {
$this->_createStream();
Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/Http/ResponseTest.php
Expand Up @@ -521,6 +521,23 @@ public function testSendWithCallableBodyWithReturn()
$this->assertEquals('the response body', ob_get_clean());
}

/**
* 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
*
Expand Down

0 comments on commit c68a773

Please sign in to comment.