Skip to content
Permalink
Browse files

Also allowing callables in Response::body() to return a string(ish)

  • Loading branch information...
lorenzo authored and ADmad committed Jul 5, 2015
1 parent c37930b commit 2cfde27978915b6c8946f266d1cb9aa92ff98df3
Showing with 21 additions and 3 deletions.
  1. +3 −3 src/Network/Response.php
  2. +18 −0 tests/TestCase/Network/ResponseTest.php
@@ -546,10 +546,10 @@ protected function _sendHeader($name, $value = null)
protected function _sendContent($content)
{
if (!is_string($content) && is_callable($content)) {
call_user_func($content);
} else {
echo $content;
$content = $content();
}
echo $content;
}
/**
@@ -331,6 +331,24 @@ public function testSendWithCallableBody()
$this->assertEquals('the response body', ob_get_clean());
}
/**
* Tests that the returned a string from a body callable is also sent
* as the response body
*
* @return void
*/
public function testSendWithCallableBodyWithReturn()
{
$response = $this->getMock('Cake\Network\Response', ['_sendHeader']);
$response->body(function () {
return 'the response body';
});
ob_start();
$response->send();
$this->assertEquals('the response body', ob_get_clean());
}
/**
* Tests the disableCache method
*

0 comments on commit 2cfde27

Please sign in to comment.
You can’t perform that action at this time.