Skip to content
Permalink
Browse files

Remove unnecessary transformation in ErrorHandlerMiddleware

Now that Network\Response is PSR7 compliant we don't need to transform
it into a Diactoros\Response. This should also fix the
IntegrationTestCase errors people have when testing error responses.
  • Loading branch information...
markstory committed Dec 3, 2016
1 parent 1338116 commit 25532d7ebd94fc819cdc600cb97583e325467fd6
@@ -17,7 +17,6 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\InstanceConfigTrait;
use Cake\Http\ResponseTransformer;
use Cake\Log\Log;
use Exception;
@@ -99,7 +98,7 @@ public function handleException($exception, $request, $response)
$res = $renderer->render();
$this->logException($request, $exception);
return ResponseTransformer::toPsr($res);
return $res;
} catch (\Exception $e) {
$this->logException($request, $e);
@@ -824,7 +824,7 @@ public function assertResponseEquals($content, $message = '')
if (!$this->_response) {
$this->fail('No response set, cannot assert content. ' . $message);
}
$this->assertEquals($content, $this->_response->body(), $message);
$this->assertEquals($content, (string)$this->_response->getBody(), $message);
}
/**
@@ -839,7 +839,7 @@ public function assertResponseContains($content, $message = '')
if (!$this->_response) {
$this->fail('No response set, cannot assert content. ' . $message);
}
$this->assertContains($content, (string)$this->_response->body(), $message);
$this->assertContains($content, (string)$this->_response->getBody(), $message);
}
/**
@@ -854,7 +854,7 @@ public function assertResponseNotContains($content, $message = '')
if (!$this->_response) {
$this->fail('No response set, cannot assert content. ' . $message);
}
$this->assertNotContains($content, (string)$this->_response->body(), $message);
$this->assertNotContains($content, (string)$this->_response->getBody(), $message);
}
/**
@@ -868,7 +868,7 @@ public function assertResponseNotEmpty($message = '')
if (!$this->_response) {
$this->fail('No response set, cannot assert content. ' . $message);
}
$this->assertNotEmpty((string)$this->_response->body(), $message);
$this->assertNotEmpty((string)$this->_response->getBody(), $message);
}
/**
* Assert response content is empty.
@@ -881,7 +881,7 @@ public function assertResponseEmpty($message = '')
if (!$this->_response) {
$this->fail('No response set, cannot assert content. ' . $message);
}
$this->assertEmpty((string)$this->_response->body(), $message);
$this->assertEmpty((string)$this->_response->getBody(), $message);
}
/**
@@ -18,12 +18,11 @@
use Cake\Error\Middleware\ErrorHandlerMiddleware;
use Cake\Http\ServerRequestFactory;
use Cake\Log\Log;
use Cake\Network\Response as CakeResponse;
use Cake\Network\Response;
use Cake\TestSuite\TestCase;
use LogicException;
use Psr\Log\LoggerInterface;
use Zend\Diactoros\Request;
use Zend\Diactoros\Response;
/**
* Test for ErrorHandlerMiddleware
@@ -111,13 +110,13 @@ public function testRendererFactory()
$factory = function ($exception) {
$this->assertInstanceOf('LogicException', $exception);
$cakeResponse = new CakeResponse;
$response = new Response;
$mock = $this->getMockBuilder('StdClass')
->setMethods(['render'])
->getMock();
$mock->expects($this->once())
->method('render')
->will($this->returnValue($cakeResponse));
->will($this->returnValue($response));
return $mock;
};
@@ -142,6 +141,8 @@ public function testHandleException()
throw new \Cake\Network\Exception\NotFoundException('whoops');
};
$result = $middleware($request, $response, $next);
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $result);
$this->assertInstanceOf('Cake\Network\Response', $result);
$this->assertNotSame($result, $response);
$this->assertEquals(404, $result->getStatusCode());
$this->assertContains("was not found", '' . $result->getBody());

0 comments on commit 25532d7

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