From 12ff8dbcc37c81e1dcdb3860f0928ae96714dfbb Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 7 Feb 2020 23:30:07 +0100 Subject: [PATCH] Start testing Route extender --- .../integration/extenders/RoutesTest.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 framework/core/tests/integration/extenders/RoutesTest.php diff --git a/framework/core/tests/integration/extenders/RoutesTest.php b/framework/core/tests/integration/extenders/RoutesTest.php new file mode 100644 index 000000000..f72569e8c --- /dev/null +++ b/framework/core/tests/integration/extenders/RoutesTest.php @@ -0,0 +1,58 @@ +send( + $this->request('GET', '/custom') + ); + + $this->assertEquals(404, $response->getStatusCode()); + } + + /** + * @test + */ + public function custom_route_can_be_added_by_extender() + { + $this->extend( + (new Extend\Routes('forum')) + ->get('/custom', 'custom', CustomRoute::class) + ); + + $response = $this->send( + $this->request('GET', '/custom') + ); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('Hello Flarumites!', $response->getBody()); + } +} + +class CustomRoute implements RequestHandlerInterface +{ + public function handle(ServerRequestInterface $request): ResponseInterface + { + return new TextResponse('Hello Flarumites!'); + } +}