From bbbd7899907baf21c88aa66a378efe2316d12551 Mon Sep 17 00:00:00 2001 From: Rathes Sachchithananthan Date: Thu, 2 Nov 2017 09:51:25 +0100 Subject: [PATCH] Adds 404 error if page not found --- src/Controllers/FrontendController.php | 3 +++ tests/FrontControllerTest.php | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Controllers/FrontendController.php b/src/Controllers/FrontendController.php index a88248b..1d7e6d0 100644 --- a/src/Controllers/FrontendController.php +++ b/src/Controllers/FrontendController.php @@ -4,6 +4,7 @@ use Aheenam\Mozhi\RouteResolver; use Aheenam\Mozhi\TemplateRenderer; use Illuminate\Routing\Controller; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class FrontendController extends Controller { @@ -16,6 +17,8 @@ public function show($slug) { $page = (new RouteResolver)->getPageByRoute($slug); + if ($page === null) throw new NotFoundHttpException(); + $view = (new TemplateRenderer($page))->render([]); return response($view, 200); diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index 7bb6f29..70ef113 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -15,4 +15,12 @@ public function it_renders_correct_view_on_route() $this->assertMatchesSnapshot($response->getContent()); } + + /** @test */ + public function it_returns_a_404_if_route_not_found() + { + $this->get('/not-found') + ->assertStatus(404); + } + } \ No newline at end of file