diff --git a/Slim/Exception/HttpMethodNotAllowedException.php b/Slim/Exception/HttpMethodNotAllowedException.php index 42eb5ca0b..6a58fd05c 100644 --- a/Slim/Exception/HttpMethodNotAllowedException.php +++ b/Slim/Exception/HttpMethodNotAllowedException.php @@ -36,6 +36,7 @@ public function getAllowedMethods(): array public function setAllowedMethods(array $methods): HttpMethodNotAllowedException { $this->allowedMethods = $methods; + $this->message = 'Method not allowed. Must be one of: ' . implode(', ', $methods); return $this; } } diff --git a/tests/Exception/HttpExceptionTest.php b/tests/Exception/HttpExceptionTest.php index 65c4250ec..48281fdca 100644 --- a/tests/Exception/HttpExceptionTest.php +++ b/tests/Exception/HttpExceptionTest.php @@ -43,8 +43,10 @@ public function testHttpNotAllowedExceptionGetAllowedMethods() $exception = new HttpMethodNotAllowedException($request); $exception->setAllowedMethods(['GET']); $this->assertEquals(['GET'], $exception->getAllowedMethods()); + $this->assertEquals('Method not allowed. Must be one of: GET', $exception->getMessage()); $exception = new HttpMethodNotAllowedException($request); $this->assertEquals([], $exception->getAllowedMethods()); + $this->assertEquals('Method not allowed.', $exception->getMessage()); } }