Skip to content

Commit

Permalink
Sort out exception decorator, tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
delboy1978uk committed Oct 27, 2019
1 parent 7772bcf commit b7c0277
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -9,7 +9,6 @@ services:
- mysql

install:
- wget http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar
- composer install

before_script:
Expand Down
2 changes: 1 addition & 1 deletion src/Mvc/Router/Decorator/ExceptionDecorator.php
Expand Up @@ -78,7 +78,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
]);
$status = ($e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500;

return $this->getResponseWithBodyAndStatus(new HtmlResponse($body), $body, $status);
return $this->getResponseWithBodyAndStatus(new HtmlResponse(), $body, $status);
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/Mvc/Router/Decorator/NotAllowedDecorator.php
Expand Up @@ -7,8 +7,9 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\HtmlResponse;

class NotAllowedDecorator extends NotFoundDecorator
class NotAllowedDecorator extends ExceptionDecorator
{
/**
* @param ServerRequestInterface $request
Expand All @@ -17,7 +18,12 @@ class NotAllowedDecorator extends NotFoundDecorator
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$this->setView('error/not-allowed');
$body = $this->viewEngine->render('error/not-allowed');
$body = $this->viewEngine->render($this->getLayout(), [
'content' => $body,
]);

return $this->getResponseWithBodyAndStatus(new HtmlResponse(''), $body, 405);

return parent::process($request, $handler);
}
Expand Down
6 changes: 1 addition & 5 deletions src/Mvc/Router/Decorator/NotFoundDecorator.php
Expand Up @@ -25,10 +25,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
'content' => $body,
]);

$stream = new Stream('php://memory', 'r+');
$stream->write($body);
$response = (new Response())->withStatus(404)->withBody($stream);

return $response;
return $this->getResponseWithBodyAndStatus(new Response\HtmlResponse(''), $body, 404);
}
}
8 changes: 8 additions & 0 deletions tests/_data/config/layouts.php
Expand Up @@ -5,4 +5,12 @@
'available_layouts' => [
'layouts/bonemvc',
],
'error_pages' => [
'exception' => 'error/error',
401 => 'error/not-authorised',
403 => 'error/not-authorised',
404 => 'error/not-found',
405 => 'error/not-allowed',
500 => 'error/error',
],
];
8 changes: 8 additions & 0 deletions tests/_data/config2/layouts.php
Expand Up @@ -5,4 +5,12 @@
'available_layouts' => [
'layouts/bonemvc',
],
'error_pages' => [
'exception' => 'error/error',
401 => 'error/not-authorised',
403 => 'error/not-authorised',
404 => 'error/not-found',
405 => 'error/not-allowed',
500 => 'error/error',
],
];
13 changes: 2 additions & 11 deletions tests/unit/BoneMvcApplicationTest.php
Expand Up @@ -50,7 +50,6 @@ public function testGetContainer()
*/
public function testCanSetSail()
{
global $_SERVER;
$application = Application::ahoy();
$application->setConfigFolder('tests/_data/config');
$_SERVER = [
Expand All @@ -71,10 +70,8 @@ public function testMethodNotAllowed()
global $_SERVER;
$application = Application::ahoy();
$application->setConfigFolder('tests/_data/config');
$_SERVER = [
'REQUEST_URI' => '/en_GB/testpackage',
'REQUEST_METHOD' => 'POST',
];
$_SERVER['REQUEST_URI'] = '/en_GB/testpackage';
$_SERVER['REQUEST_METHOD'] = 'POST';
ob_start();
$this->assertTrue($application->setSail());
$contents = ob_get_contents();
Expand All @@ -99,7 +96,6 @@ public function testMethodNotAllowed()
*/
public function testApi()
{
global $_SERVER;
$application = Application::ahoy();
$application->setConfigFolder('tests/_data/config');
$_SERVER = [
Expand All @@ -117,7 +113,6 @@ public function testApi()
*/
public function testException()
{
global $_SERVER;
$application = Application::ahoy();
$application->setConfigFolder('tests/_data/config');
$_SERVER = [
Expand All @@ -136,7 +131,6 @@ public function testException()
*/
public function testJsonResponse()
{
global $_SERVER;
$application = Application::ahoy();
$application->setConfigFolder('tests/_data/config');
$_SERVER = [
Expand All @@ -154,7 +148,6 @@ public function testJsonResponse()
*/
public function test404Request()
{
global $_SERVER;
$application = Application::ahoy();
$application->setConfigFolder('tests/_data/config');
$_SERVER = [
Expand All @@ -174,7 +167,6 @@ public function test404Request()
*/
public function testRedirectToLocalisedURL()
{
global $_SERVER;
$application = Application::ahoy();
$application->setConfigFolder('tests/_data/config');
$_SERVER = [
Expand All @@ -194,7 +186,6 @@ public function testRedirectToLocalisedURL()
*/
public function testWithoutI18n()
{
global $_SERVER;
$application = Application::ahoy();
$application->setConfigFolder('tests/_data/config2');
$_SERVER = [
Expand Down

0 comments on commit b7c0277

Please sign in to comment.