-
Notifications
You must be signed in to change notification settings - Fork 13
Raise exception in Route constructor when no HTTP methods provided #59
Raise exception in Route constructor when no HTTP methods provided #59
Conversation
Routes _require_ one or more HTTP methods in order to be valid.
@@ -160,6 +160,12 @@ public function getOptions() : array | |||
*/ | |||
private function validateHttpMethods(array $methods) : array | |||
{ | |||
if (empty($methods)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have here just ! $methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the argument is typed as an array, this makes it more semantically clear that we're checking to see if we have an empty array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the result will be exactly the same and everywhere we are using just !
, but fine - whatever you prefer, both works the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware the results will be the same. Readability and intent are important, however!
@@ -178,7 +178,7 @@ public function testCommonHttpMethodsAreExposedAsClassMethodsAndReturnRoutes($me | |||
public function testCreatingHttpRouteMethodWithExistingPathButDifferentMethodCreatesNewRouteInstance() | |||
{ | |||
$this->router->addRoute(Argument::type(Route::class))->shouldBeCalledTimes(2); | |||
$route = $this->middleware->route('/foo', $this->noopMiddleware, []); | |||
$route = $this->middleware->route('/foo', $this->noopMiddleware, ['POST']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use RequestMethod::METHOD_POST
(for consistency)
test/RouteTest.php
Outdated
@@ -71,13 +71,13 @@ public function testRouteCanMatchMethod() | |||
|
|||
public function testRouteHeadMethodIsNotAllowedByDefault() | |||
{ | |||
$route = new Route('/foo', $this->noopMiddleware, []); | |||
$route = new Route('/foo', $this->noopMiddleware, ['GET']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also here and in following tests
Routes require one or more HTTP methods in order to be valid.