From a05cd243c373afdf63e55b512c7caaa1159a1f5d Mon Sep 17 00:00:00 2001 From: Hat Dao Date: Tue, 5 Jan 2016 11:36:22 +0700 Subject: [PATCH 1/2] Add error method not allowed to Response Factory --- src/Http/Response/Factory.php | 14 ++++++++++++++ tests/Http/Response/FactoryTest.php | 8 ++++++++ 2 files changed, 22 insertions(+) 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/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']); From ce7592c6b53f0cd2e81b5745ffde4876dd429659 Mon Sep 17 00:00:00 2001 From: Hat Dao Date: Tue, 5 Jan 2016 11:40:38 +0700 Subject: [PATCH 2/2] Fix as StyleCI and add PhpStorm project files to gitignore --- .gitignore | 1 + src/Routing/Router.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) 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/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;