diff --git a/.gitignore b/.gitignore index 23c30d909..866040f7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .php_cs.cache +.idea composer.lock phpunit.xml storage diff --git a/src/Http/Response/Factory.php b/src/Http/Response/Factory.php index 2d503c554..b3dd0a355 100644 --- a/src/Http/Response/Factory.php +++ b/src/Http/Response/Factory.php @@ -233,6 +233,20 @@ public function errorUnauthorized($message = 'Unauthorized') $this->error($message, 401); } + /** + * Return a 405 method not allowed error. + * + * @param string $message + * + * @throws \Symfony\Component\HttpKernel\Exception\HttpException + * + * @return void + */ + public function errorMethodNotAllowed($message = 'Method Not Allowed') + { + $this->error($message, 405); + } + /** * Call magic methods beginning with "with". * diff --git a/src/Routing/Router.php b/src/Routing/Router.php index eea6a57a9..e88cac6e4 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -14,7 +14,6 @@ use Dingo\Api\Contract\Routing\Adapter; use Illuminate\Routing\ControllerInspector; use Dingo\Api\Contract\Debug\ExceptionHandler; -use Dingo\Api\Http\Parser\Accept as AcceptParser; use Illuminate\Http\Response as IlluminateResponse; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; diff --git a/tests/Http/Response/FactoryTest.php b/tests/Http/Response/FactoryTest.php index da84c1b97..96e44db02 100644 --- a/tests/Http/Response/FactoryTest.php +++ b/tests/Http/Response/FactoryTest.php @@ -132,6 +132,14 @@ public function testUnauthorizedThrowsHttpException() $this->factory->errorUnauthorized(); } + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testMethodNotAllowedThrowsHttpException() + { + $this->factory->errorMethodNotAllowed(); + } + public function testMakingArrayResponse() { $response = $this->factory->array(['foo' => 'bar']);