Skip to content

Commit eee00c5

Browse files
authored
Merge pull request #453 from cakephp/streamed-html
Fix warnings when streaming HTML responses are used.
2 parents 26123f6 + a192ef9 commit eee00c5

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

src/Routing/Filter/DebugBarFilter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ protected function _injectScripts($id, $response)
233233
return;
234234
}
235235
$body = $response->body();
236+
if (!is_string($body)) {
237+
return;
238+
}
236239
$pos = strrpos($body, '</body>');
237240
if ($pos === false) {
238241
return;

tests/TestCase/Cache/Engine/DebugEngineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DebugEngineTest extends TestCase
4242
public function setUp()
4343
{
4444
parent::setUp();
45-
$mock = $this->getMock('Cake\Cache\CacheEngine');
45+
$mock = $this->getMockBuilder('Cake\Cache\CacheEngine')->getMock();
4646
$this->mock = $mock;
4747
$this->engine = new DebugEngine($mock);
4848
$this->engine->init();

tests/TestCase/Controller/ToolbarControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testClearCacheNoGet()
6969
*/
7070
public function testClearCache()
7171
{
72-
$mock = $this->getMock('Cake\Cache\CacheEngine');
72+
$mock = $this->getMockBuilder('Cake\Cache\CacheEngine')->getMock();
7373
$mock->expects($this->once())
7474
->method('init')
7575
->will($this->returnValue(true));

tests/TestCase/Database/Log/DebugLogTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testLog()
6969
*/
7070
public function testLogDecorates()
7171
{
72-
$orig = $this->getMock('Cake\Database\Log\QueryLogger');
72+
$orig = $this->getMockBuilder('Cake\Database\Log\QueryLogger')->getMock();
7373
$orig->expects($this->once())
7474
->method('log');
7575

tests/TestCase/Routing/Filter/DebugBarFilterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,31 @@ public function testAfterDispatchIgnoreRequestAction()
109109
$this->assertNotContains('<script>', $response->body());
110110
}
111111

112+
/**
113+
* Test that afterDispatch ignores streaming bodies
114+
*
115+
* @return void
116+
*/
117+
public function testAfterDispatchIgnoreStreamBodies()
118+
{
119+
$request = new Request([
120+
'url' => '/articles',
121+
'params' => ['plugin' => null]
122+
]);
123+
$response = new Response([
124+
'statusCode' => 200,
125+
'type' => 'text/html',
126+
]);
127+
$response->body(function () {
128+
echo 'I am a teapot!';
129+
});
130+
131+
$bar = new DebugBarFilter($this->events, []);
132+
$event = new Event('Dispatcher.afterDispatch', $bar, compact('request', 'response'));
133+
$this->assertNull($bar->afterDispatch($event));
134+
$this->assertInstanceOf('Closure', $response->body());
135+
}
136+
112137
/**
113138
* Test that afterDispatch saves panel data.
114139
*

0 commit comments

Comments
 (0)