From 2fb59854be44575bad7a5012b0dda27e110e5249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Mon, 22 Mar 2021 18:33:16 +0100 Subject: [PATCH 1/2] [BUGFIX] Issue #439: Fixed multiple request-type on same routes. --- src/Pecee/SimpleRouter/Router.php | 15 ++++++++++----- tests/Pecee/SimpleRouter/RouterRouteTest.php | 12 ++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Pecee/SimpleRouter/Router.php b/src/Pecee/SimpleRouter/Router.php index 758204f..d9e642b 100644 --- a/src/Pecee/SimpleRouter/Router.php +++ b/src/Pecee/SimpleRouter/Router.php @@ -262,8 +262,8 @@ class Router /** * Load routes - * @throws NotFoundHttpException * @return void + * @throws NotFoundHttpException */ public function loadRoutes(): void { @@ -350,7 +350,7 @@ class Router { $this->debug('Routing request'); - $methodNotAllowed = false; + $methodNotAllowed = null; try { $url = $this->request->getRewriteUrl() ?? $this->request->getUrl()->getPath(); @@ -370,7 +370,12 @@ class Router /* Check if request method matches */ if (\count($route->getRequestMethods()) !== 0 && \in_array($this->request->getMethod(), $route->getRequestMethods(), true) === false) { $this->debug('Method "%s" not allowed', $this->request->getMethod()); - $methodNotAllowed = true; + + // Only set method not allowed is not already set + if ($methodNotAllowed === null) { + $methodNotAllowed = true; + } + continue; } @@ -475,9 +480,9 @@ class Router /** * @param \Exception $e - * @throws HttpException - * @throws \Exception * @return string|null + * @throws \Exception + * @throws HttpException */ protected function handleException(\Exception $e): ?string { diff --git a/tests/Pecee/SimpleRouter/RouterRouteTest.php b/tests/Pecee/SimpleRouter/RouterRouteTest.php index e92bd37..c416ecc 100644 --- a/tests/Pecee/SimpleRouter/RouterRouteTest.php +++ b/tests/Pecee/SimpleRouter/RouterRouteTest.php @@ -210,4 +210,16 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase $this->assertTrue(true); } + public function testSameRoutes() + { + + TestRouter::get('/recipe', 'DummyController@method1')->name('add'); + TestRouter::post('/recipe', 'DummyController@method2')->name('edit'); + + TestRouter::debugNoReset('/recipe', 'post'); + TestRouter::debug('/recipe', 'get'); + + $this->assertTrue(true); + } + } \ No newline at end of file From f74252e8cc4ba567f07ff045ee64153ea22a04e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Mon, 22 Mar 2021 18:34:14 +0100 Subject: [PATCH 2/2] Removed newline --- tests/Pecee/SimpleRouter/RouterRouteTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Pecee/SimpleRouter/RouterRouteTest.php b/tests/Pecee/SimpleRouter/RouterRouteTest.php index c416ecc..28a7b4e 100644 --- a/tests/Pecee/SimpleRouter/RouterRouteTest.php +++ b/tests/Pecee/SimpleRouter/RouterRouteTest.php @@ -212,7 +212,6 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase public function testSameRoutes() { - TestRouter::get('/recipe', 'DummyController@method1')->name('add'); TestRouter::post('/recipe', 'DummyController@method2')->name('edit');