Browse Source

Fix failing deprecated method use in ExceptionRenderer tests.

Fix a bunch of related things as they were in the call stack as well.
mark_story 8 years ago
parent
commit
a158d437f9

+ 5 - 4
src/Controller/Component/RequestHandlerComponent.php

@@ -331,7 +331,7 @@ class RequestHandlerComponent extends Component
         if ($this->ext && $isRecognized) {
             $this->renderAs($controller, $this->ext);
         } else {
-            $response->charset(Configure::read('App.encoding'));
+            $controller->response = $response->withCharset(Configure::read('App.encoding'));
         }
 
         if ($this->_config['checkHttpCache'] &&
@@ -652,14 +652,15 @@ class RequestHandlerComponent extends Component
             return false;
         }
         if (!$request->getParam('requested')) {
-            $response->type($cType);
+            $response = $response->withType($cType);
         }
         if (!empty($options['charset'])) {
-            $response->charset($options['charset']);
+            $response = $response->withCharset($options['charset']);
         }
         if (!empty($options['attachment'])) {
-            $response->download($options['attachment']);
+            $response = $response->withDownload($options['attachment']);
         }
+        $controller->response = $response;
 
         return true;
     }

+ 9 - 2
src/Core/Exception/Exception.php

@@ -86,11 +86,11 @@ class Exception extends RuntimeException
     /**
      * Get/set the response header to be used
      *
-     * See also Cake\Http\Response::header()
+     * See also Cake\Http\Response::withHeader()
      *
      * @param string|array|null $header An array of header strings or a single header string
      *  - an associative array of "header name" => "header value"
-     *  - an array of string headers is also accepted
+     *  - an array of string headers is also accepted (deprecated)
      * @param string|null $value The header value.
      * @return array
      */
@@ -100,6 +100,13 @@ class Exception extends RuntimeException
             return $this->_responseHeaders;
         }
         if (is_array($header)) {
+            if (isset($header[0])) {
+                deprecationWarning(
+                    'Passing a list string headers to Exception::responseHeader() is deprecated. ' .
+                    'Use an associative array instead.'
+                );
+            }
+
             return $this->_responseHeaders = $header;
         }
         $this->_responseHeaders = [$header => $value];

+ 13 - 8
src/Error/ExceptionRenderer.php

@@ -21,7 +21,7 @@ use Cake\Core\Exception\Exception as CakeException;
 use Cake\Core\Exception\MissingPluginException;
 use Cake\Event\Event;
 use Cake\Http\Response;
-use Cake\Http\ServerRequest;
+use Cake\Http\ServerRequestFactory;
 use Cake\Network\Exception\HttpException;
 use Cake\Routing\DispatcherFactory;
 use Cake\Routing\Router;
@@ -115,7 +115,7 @@ class ExceptionRenderer implements ExceptionRendererInterface
     protected function _getController()
     {
         if (!$request = Router::getRequest(true)) {
-            $request = ServerRequest::createFromGlobals();
+            $request = ServerRequestFactory::fromGlobals();
         }
         $response = new Response();
         $controller = null;
@@ -169,11 +169,15 @@ class ExceptionRenderer implements ExceptionRendererInterface
 
         $message = $this->_message($exception, $code);
         $url = $this->controller->request->getRequestTarget();
+        $response = $this->controller->response;
 
         if ($exception instanceof CakeException) {
-            $this->controller->response->header($exception->responseHeader());
+            foreach ((array)$exception->responseHeader() as $key => $value) {
+                $response = $response->withHeader($key, $value);
+            }
         }
-        $this->controller->response->statusCode($code);
+        $response = $response->withStatus($code);
+
         $viewVars = [
             'message' => $message,
             'url' => h($url),
@@ -197,6 +201,7 @@ class ExceptionRenderer implements ExceptionRendererInterface
             $this->controller->set($unwrapped->getAttributes());
         }
 
+        $this->controller->response = $response;
         return $this->_outputMessage($template);
     }
 
@@ -212,8 +217,7 @@ class ExceptionRenderer implements ExceptionRendererInterface
         $result = call_user_func([$this, $method], $exception);
         $this->_shutdown();
         if (is_string($result)) {
-            $this->controller->response->body($result);
-            $result = $this->controller->response;
+            $result = $this->controller->response->withStringBody($result);
         }
 
         return $result;
@@ -361,8 +365,9 @@ class ExceptionRenderer implements ExceptionRendererInterface
             ->setTemplatePath('Error');
         $view = $this->controller->createView('View');
 
-        $this->controller->response->body($view->render($template, 'error'));
-        $this->controller->response->type('html');
+        $this->controller->response = $this->controller->response
+            ->withType('html')
+            ->withStringBody($view->render($template, 'error'));
 
         return $this->controller->response;
     }

+ 16 - 12
src/Http/Response.php

@@ -484,9 +484,7 @@ class Response implements ResponseInterface
      */
     public function send()
     {
-        deprecationWarning(
-            'Will be removed in 4.0.0'
-        );
+        deprecationWarning('Response::send() will be removed in 4.0.0');
 
         if ($this->hasHeader('Location') && $this->_status === 200) {
             $this->statusCode(302);
@@ -1625,7 +1623,7 @@ class Response implements ResponseInterface
     {
         deprecationWarning(
             'Response::modified() is deprecated. ' .
-            'Use withModified() instead.'
+            'Use withModified() or getHeaderLine("Last-Modified") instead.'
         );
 
         if ($time !== null) {
@@ -1668,12 +1666,14 @@ class Response implements ResponseInterface
      * setting the status code to "304 Not Modified" and removing all
      * conflicting headers
      *
+     * *Warning* This method mutates the response in-place and should be avoided.
+     *
      * @return void
      */
     public function notModified()
     {
-        $this->statusCode(304);
-        $this->body('');
+        $this->_status = 304;
+        $this->_createStream();
 
         $remove = [
             'Allow',
@@ -1790,7 +1790,7 @@ class Response implements ResponseInterface
     {
         deprecationWarning(
             'Response::etag() is deprecated. ' .
-            'Use withEtag() instead.'
+            'Use withEtag() or getHeaderLine("Etag") instead.'
         );
 
         if ($hash !== null) {
@@ -1976,18 +1976,22 @@ class Response implements ResponseInterface
      * the Last-Modified etag response header before calling this method. Otherwise
      * a comparison will not be possible.
      *
+     * *Warning* This method mutates the response in-place and should be avoided.
+     *
      * @param \Cake\Http\ServerRequest $request Request object
      * @return bool Whether the response was marked as not modified or not.
      */
     public function checkNotModified(ServerRequest $request)
     {
-        $etags = preg_split('/\s*,\s*/', (string)$request->header('If-None-Match'), 0, PREG_SPLIT_NO_EMPTY);
-        $modifiedSince = $request->header('If-Modified-Since');
-        if ($responseTag = $this->etag()) {
+        $etags = preg_split('/\s*,\s*/', (string)$request->getHeaderLine('If-None-Match'), 0, PREG_SPLIT_NO_EMPTY);
+        $responseTag = $this->getHeaderLine('Etag');
+        if ($responseTag) {
             $etagMatches = in_array('*', $etags) || in_array($responseTag, $etags);
         }
-        if ($modifiedSince) {
-            $timeMatches = strtotime($this->modified()) === strtotime($modifiedSince);
+
+        $modifiedSince = $request->getHeaderLine('If-Modified-Since');
+        if ($modifiedSince && $this->hasHeader('Last-Modified')) {
+            $timeMatches = strtotime($this->getHeaderLine('Last-Modifed')) === strtotime($modifiedSince);
         }
         $checks = compact('etagMatches', 'timeMatches');
         if (empty($checks)) {

+ 5 - 1
src/Template/Error/missing_template.ctp

@@ -28,7 +28,11 @@ $this->start('subheading');
     <?= sprintf('The template %s</em> was not found.', h($file)); ?>
 <?php else: ?>
     <strong>Error: </strong>
-    <?= sprintf('The view for <em>%sController::%s()</em> was not found.', h(Inflector::camelize($this->request->controller)), h($this->request->action)); ?>
+    <?= sprintf(
+        'The view for <em>%sController::%s()</em> was not found.',
+        h(Inflector::camelize($this->request->getParam('controller'))),
+        h($this->request->getParam('action'))
+    ); ?>
 <?php endif ?>
 <?php $this->end() ?>
 

+ 1 - 1
src/Template/Error/pdo_error.ctp

@@ -14,7 +14,7 @@
  */
 use Cake\Error\Debugger;
 
-$this->layout = 'dev_error';
+$this->setLayout('dev_error');
 
 $this->assign('title', 'Database Error');
 $this->assign('templateName', 'pdo_error.ctp');

+ 73 - 150
tests/TestCase/Error/ExceptionRendererTest.php

@@ -185,20 +185,6 @@ class ExceptionRendererTest extends TestCase
     }
 
     /**
-     * Mocks out the response on the ExceptionRenderer object so headers aren't modified.
-     *
-     * @return void
-     */
-    protected function _mockResponse($error)
-    {
-        $error->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['_sendHeader'])
-            ->getMock();
-
-        return $error;
-    }
-
-    /**
      * test that methods declared in an ExceptionRenderer subclass are not converted
      * into error400 when debug > 0
      *
@@ -207,11 +193,11 @@ class ExceptionRendererTest extends TestCase
     public function testSubclassMethodsNotBeingConvertedToError()
     {
         $exception = new MissingWidgetThingException('Widget not found');
-        $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));
+        $ExceptionRenderer = new MyCustomExceptionRenderer($exception);
 
         $result = $ExceptionRenderer->render();
 
-        $this->assertEquals('widget thing is missing', $result->body());
+        $this->assertEquals('widget thing is missing', (string)$result->getBody());
     }
 
     /**
@@ -223,14 +209,14 @@ class ExceptionRendererTest extends TestCase
     {
         Configure::write('debug', false);
         $exception = new MissingWidgetThingException('Widget not found');
-        $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));
+        $ExceptionRenderer = new MyCustomExceptionRenderer($exception);
 
         $result = $ExceptionRenderer->render();
 
         $this->assertEquals('missingWidgetThing', $ExceptionRenderer->method);
         $this->assertEquals(
             'widget thing is missing',
-            $result->body(),
+            (string)$result->getBody(),
             'Method declared in subclass converted to error400'
         );
     }
@@ -245,13 +231,13 @@ class ExceptionRendererTest extends TestCase
         Configure::write('debug', false);
 
         $exception = new MissingControllerException('PostsController');
-        $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));
+        $ExceptionRenderer = new MyCustomExceptionRenderer($exception);
 
         $result = $ExceptionRenderer->render();
 
         $this->assertRegExp(
             '/Not Found/',
-            $result->body(),
+            (string)$result->getBody(),
             'Method declared in error handler not converted to error400. %s'
         );
     }
@@ -279,12 +265,12 @@ class ExceptionRendererTest extends TestCase
     {
         Configure::write('debug', false);
         $exception = new MissingActionException('Secret info not to be leaked');
-        $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));
+        $ExceptionRenderer = new ExceptionRenderer($exception);
 
         $this->assertInstanceOf('Cake\Controller\ErrorController', $ExceptionRenderer->controller);
         $this->assertEquals($exception, $ExceptionRenderer->error);
 
-        $result = $ExceptionRenderer->render()->body();
+        $result = (string)$ExceptionRenderer->render()->getBody();
 
         $this->assertEquals('error400', $ExceptionRenderer->template);
         $this->assertContains('Not Found', $result);
@@ -300,10 +286,10 @@ class ExceptionRendererTest extends TestCase
     {
         static::setAppNamespace();
         $exception = new SocketException('socket exception');
-        $renderer = $this->_mockResponse(new \TestApp\Error\TestAppsExceptionRenderer($exception));
+        $renderer = new \TestApp\Error\TestAppsExceptionRenderer($exception);
 
         $result = $renderer->render();
-        $this->assertContains('<b>peeled</b>', $result->body());
+        $this->assertContains('<b>peeled</b>', (string)$result->getBody());
     }
 
     /**
@@ -315,15 +301,11 @@ class ExceptionRendererTest extends TestCase
     {
         $exception = new MissingWidgetThingException('coding fail.');
         $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(404);
-
-        $result = $ExceptionRenderer->render();
+        $response = $ExceptionRenderer->render();
 
+        $this->assertEquals(404, $response->getStatusCode());
         $this->assertFalse(method_exists($ExceptionRenderer, 'missingWidgetThing'), 'no method should exist.');
-        $this->assertContains('coding fail', $result->body(), 'Text should show up.');
+        $this->assertContains('coding fail', (string)$response->getBody(), 'Text should show up.');
     }
 
     /**
@@ -335,16 +317,10 @@ class ExceptionRendererTest extends TestCase
     {
         $exception = new \OutOfBoundsException('foul ball.');
         $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())
-            ->method('statusCode')
-            ->with(500);
-
         $result = $ExceptionRenderer->render();
 
-        $this->assertContains('foul ball.', $result->body(), 'Text should show up as its debug mode.');
+        $this->assertEquals(500, $result->getStatusCode());
+        $this->assertContains('foul ball.', (string)$result->getBody(), 'Text should show up as its debug mode.');
     }
 
     /**
@@ -358,15 +334,11 @@ class ExceptionRendererTest extends TestCase
 
         $exception = new \OutOfBoundsException('foul ball.');
         $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())
-            ->method('statusCode')
-            ->with(500);
 
-        $result = $ExceptionRenderer->render()->body();
+        $response = $ExceptionRenderer->render();
+        $result = (string)$response->getBody();
 
+        $this->assertEquals(500, $response->getStatusCode());
         $this->assertNotContains('foul ball.', $result, 'Text should no show up.');
         $this->assertContains('Internal Error', $result, 'Generic message only.');
     }
@@ -380,14 +352,11 @@ class ExceptionRendererTest extends TestCase
     {
         $exception = new \OutOfBoundsException('foul ball.', 501);
         $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(501);
-
-        $result = $ExceptionRenderer->render();
+        $response = $ExceptionRenderer->render();
+        $result = (string)$response->getBody();
 
-        $this->assertContains('foul ball.', $result->body(), 'Text should show up as its debug mode.');
+        $this->assertEquals(501, $response->getStatusCode());
+        $this->assertContains('foul ball.', $result, 'Text should show up as its debug mode.');
     }
 
     /**
@@ -404,13 +373,11 @@ class ExceptionRendererTest extends TestCase
 
         $exception = new NotFoundException('Custom message');
         $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(404);
 
-        $result = $ExceptionRenderer->render()->body();
+        $response = $ExceptionRenderer->render();
+        $result = (string)$response->getBody();
 
+        $this->assertEquals(404, $response->getStatusCode());
         $this->assertContains('<h2>Custom message</h2>', $result);
         $this->assertRegExp("/<strong>'.*?\/posts\/view\/1000'<\/strong>/", $result);
     }
@@ -432,12 +399,9 @@ class ExceptionRendererTest extends TestCase
         $exception = new NotFoundException('Custom message');
         $exceptionLine = __LINE__ - 1;
         $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Network\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(404);
 
-        $result = $ExceptionRenderer->render()->body();
+        $response = $ExceptionRenderer->render();
+        $result = (string)$response->getBody();
         $expected = [
             'message' => 'Custom message',
             'url' => '/posts/view/1000?sort=title&amp;direction=desc',
@@ -445,8 +409,8 @@ class ExceptionRendererTest extends TestCase
             'file' => __FILE__,
             'line' => $exceptionLine
         ];
-
         $this->assertEquals($expected, json_decode($result, true));
+        $this->assertEquals(404, $response->getStatusCode());
     }
 
     /**
@@ -459,16 +423,16 @@ class ExceptionRendererTest extends TestCase
         Configure::write('debug', false);
 
         $exception = new NotFoundException('Custom message');
-        $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));
+        $ExceptionRenderer = new ExceptionRenderer($exception);
 
         $result = $ExceptionRenderer->render();
-        $this->assertContains('Custom message', $result->body());
+        $this->assertContains('Custom message', (string)$result->getBody());
 
         $exception = new MissingActionException(['controller' => 'PostsController', 'action' => 'index']);
-        $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));
+        $ExceptionRenderer = new ExceptionRenderer($exception);
 
         $result = $ExceptionRenderer->render();
-        $this->assertContains('Not Found', $result->body());
+        $this->assertContains('Not Found', (string)$result->getBody());
     }
 
     /**
@@ -484,9 +448,9 @@ class ExceptionRendererTest extends TestCase
         Router::setRequestInfo($request);
 
         $exception = new NotFoundException('Custom message');
-        $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));
+        $ExceptionRenderer = new ExceptionRenderer($exception);
 
-        $result = $ExceptionRenderer->render()->body();
+        $result = (string)$ExceptionRenderer->render()->getBody();
 
         $this->assertNotContains('<script>document', $result);
         $this->assertNotContains('alert(t);</script>', $result);
@@ -501,14 +465,12 @@ class ExceptionRendererTest extends TestCase
     {
         $exception = new InternalErrorException('An Internal Error Has Occurred.');
         $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(500);
 
-        $result = $ExceptionRenderer->render();
-        $this->assertContains('<h2>An Internal Error Has Occurred.</h2>', $result->body());
-        $this->assertContains('An Internal Error Has Occurred.</p>', $result->body());
+        $response = $ExceptionRenderer->render();
+        $result = (string)$response->getBody();
+        $this->assertEquals(500, $response->getStatusCode());
+        $this->assertContains('<h2>An Internal Error Has Occurred.</h2>', $result);
+        $this->assertContains('An Internal Error Has Occurred.</p>', $result);
     }
 
     /**
@@ -519,13 +481,12 @@ class ExceptionRendererTest extends TestCase
     public function testExceptionResponseHeader()
     {
         $exception = new MethodNotAllowedException('Only allowing POST and DELETE');
-        $exception->responseHeader(['Allow: POST, DELETE']);
+        $exception->responseHeader(['Allow' => 'POST, DELETE']);
         $ExceptionRenderer = new ExceptionRenderer($exception);
 
         $result = $ExceptionRenderer->render();
-        $headers = $result->header();
-        $this->assertArrayHasKey('Allow', $headers);
-        $this->assertEquals('POST, DELETE', $headers['Allow']);
+        $this->assertTrue($result->hasHeader('Allow'));
+        $this->assertEquals('POST, DELETE', $result->getHeaderLine('Allow'));
     }
 
     /**
@@ -540,9 +501,9 @@ class ExceptionRendererTest extends TestCase
             'prefix' => '',
             'plugin' => '',
         ]);
-        $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));
+        $ExceptionRenderer = new MyCustomExceptionRenderer($exception);
 
-        $result = $ExceptionRenderer->render()->body();
+        $result = (string)$ExceptionRenderer->render()->getBody();
 
         $this->assertEquals('missingController', $ExceptionRenderer->template);
         $this->assertContains('Missing Controller', $result);
@@ -561,9 +522,9 @@ class ExceptionRendererTest extends TestCase
             'prefix' => '',
             'plugin' => '',
         ]);
-        $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));
+        $ExceptionRenderer = new MyCustomExceptionRenderer($exception);
 
-        $result = $ExceptionRenderer->render()->body();
+        $result = (string)$ExceptionRenderer->render()->getBody();
 
         $this->assertEquals('missingController', $ExceptionRenderer->template);
         $this->assertContains('Missing Controller', $result);
@@ -706,18 +667,13 @@ class ExceptionRendererTest extends TestCase
      */
     public function testCakeExceptionHandling($exception, $patterns, $code)
     {
-        $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())
-            ->method('statusCode')
-            ->with($code);
-
-        $result = $ExceptionRenderer->render()->body();
+        $exceptionRenderer = new ExceptionRenderer($exception);
+        $response = $exceptionRenderer->render();
 
+        $this->assertEquals($code, $response->getStatusCode());
+        $body = (string)$response->getBody();
         foreach ($patterns as $pattern) {
-            $this->assertRegExp($pattern, $result);
+            $this->assertRegExp($pattern, $body);
         }
     }
 
@@ -730,7 +686,7 @@ class ExceptionRendererTest extends TestCase
     {
         $exceptionRenderer = new MyCustomExceptionRenderer(new MissingWidgetThing());
 
-        $result = $exceptionRenderer->render()->body();
+        $result = (string)$exceptionRenderer->render()->getBody();
         $this->assertContains('widget thing is missing', $result);
     }
 
@@ -754,15 +710,10 @@ class ExceptionRendererTest extends TestCase
             ->with('missingHelper')
             ->will($this->throwException($exception));
 
-        $response = $this->getMockBuilder('Cake\Http\Response')->getMock();
-        $response->expects($this->once())
-            ->method('body')
-            ->with($this->stringContains('Helper class Fail'));
-
-        $ExceptionRenderer->controller->response = $response;
-        $ExceptionRenderer->render();
+        $response = $ExceptionRenderer->render();
         sort($ExceptionRenderer->controller->helpers);
         $this->assertEquals(['Form', 'Html'], $ExceptionRenderer->controller->helpers);
+        $this->assertContains('Helper class Fail', (string)$response->getBody());
     }
 
     /**
@@ -783,13 +734,8 @@ class ExceptionRendererTest extends TestCase
             ->method('beforeRender')
             ->will($this->throwException($exception));
 
-        $response = $this->getMockBuilder('Cake\Http\Response')->getMock();
-        $response->expects($this->once())
-            ->method('body')
-            ->with($this->stringContains('Not there, sorry'));
-
-        $ExceptionRenderer->controller->response = $response;
-        $ExceptionRenderer->render();
+        $response = $ExceptionRenderer->render();
+        $this->assertContains('Not there, sorry', (string)$response->getBody());
     }
 
     /**
@@ -814,17 +760,9 @@ class ExceptionRendererTest extends TestCase
         );
         $ExceptionRenderer->controller->request = new ServerRequest;
 
-        $response = $this->getMockBuilder('Cake\Http\Response')->getMock();
-        $response->expects($this->once())
-            ->method('body')
-            ->with($this->stringContains('Not Found'));
-        $response->expects($this->once())
-            ->method('type')
-            ->with('html');
-
-        $ExceptionRenderer->controller->response = $response;
-
-        $ExceptionRenderer->render();
+        $response = $ExceptionRenderer->render();
+        $this->assertEquals('text/html', $response->getType());
+        $this->assertContains('Not Found', (string)$response->getBody());
         $this->assertTrue($this->called, 'Listener added was not triggered.');
         $this->assertEquals('', $ExceptionRenderer->controller->viewBuilder()->layoutPath());
         $this->assertEquals('Error', $ExceptionRenderer->controller->viewBuilder()->templatePath());
@@ -852,16 +790,10 @@ class ExceptionRendererTest extends TestCase
             ->with('error400')
             ->will($this->throwException($exception));
 
-        $response = $this->getMockBuilder('Cake\Http\Response')->getMock();
-        $response->expects($this->once())
-            ->method('body')
-            ->with($this->logicalAnd(
-                $this->logicalNot($this->stringContains('test plugin error500')),
-                $this->stringContains('Not Found')
-            ));
-
-        $ExceptionRenderer->controller->response = $response;
-        $ExceptionRenderer->render();
+        $response = $ExceptionRenderer->render();
+        $body = (string)$response->getBody();
+        $this->assertNotContains('test plugin error500', $body);
+        $this->assertContains('Not Found', $body);
     }
 
     /**
@@ -887,16 +819,10 @@ class ExceptionRendererTest extends TestCase
             ->with('error400')
             ->will($this->throwException($exception));
 
-        $response = $this->getMockBuilder('Cake\Http\Response')->getMock();
-        $response->expects($this->once())
-            ->method('body')
-            ->with($this->logicalAnd(
-                $this->stringContains('test plugin error500'),
-                $this->stringContains('Not Found')
-            ));
-
-        $ExceptionRenderer->controller->response = $response;
-        $ExceptionRenderer->render();
+        $response = $ExceptionRenderer->render();
+        $body = (string)$response->getBody();
+        $this->assertContains('test plugin error500', $body);
+        $this->assertContains('Not Found', $body);
         Plugin::unload();
     }
 
@@ -915,8 +841,8 @@ class ExceptionRendererTest extends TestCase
         $ExceptionRenderer = new ExceptionRenderer($exception);
         $result = $ExceptionRenderer->render();
 
-        $this->assertContains('Internal Error', $result->body());
-        $this->assertEquals(500, $result->statusCode());
+        $this->assertContains('Internal Error', (string)$result->getBody());
+        $this->assertEquals(500, $result->getStatusCode());
     }
 
     /**
@@ -980,7 +906,7 @@ class ExceptionRendererTest extends TestCase
         $events->on('Dispatcher.afterDispatch', $listener);
 
         $exception = new MissingWidgetThingException('Widget not found');
-        $renderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));
+        $renderer = new MyCustomExceptionRenderer($exception);
         $renderer->render();
 
         $expected = ['Controller.shutdown', 'Dispatcher.afterDispatch'];
@@ -998,13 +924,10 @@ class ExceptionRendererTest extends TestCase
         $exception->queryString = 'SELECT * from poo_query < 5 and :seven';
         $exception->params = ['seven' => 7];
         $ExceptionRenderer = new ExceptionRenderer($exception);
-        $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')
-            ->setMethods(['statusCode', '_sendHeader'])
-            ->getMock();
-        $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(500);
-
-        $result = $ExceptionRenderer->render()->body();
+        $response = $ExceptionRenderer->render();
 
+        $this->assertEquals(500, $response->getStatusCode());
+        $result = (string)$response->getBody();
         $this->assertContains('Database Error', $result);
         $this->assertContains('There was an error in the SQL query', $result);
         $this->assertContains(h('SELECT * from poo_query < 5 and :seven'), $result);