Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

We are not translating HTTP_METHOD_ANY to ['*'] #60

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/RouteResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class RouteResult implements MiddlewareInterface
{
/**
* @var array
* @var null|string[]
*/
private $allowedMethods = [];

Expand Down Expand Up @@ -88,14 +88,7 @@ public static function fromRouteFailure(?array $methods) : self
{
$result = new self();
$result->success = false;

if ($methods === Route::HTTP_METHOD_ANY) {
$result->allowedMethods = ['*'];
}

if (is_array($methods)) {
$result->allowedMethods = $methods;
}
$result->allowedMethods = $methods;

return $result;
}
Expand Down Expand Up @@ -180,7 +173,7 @@ public function isFailure() : bool
*/
public function isMethodFailure() : bool
{
if ($this->isSuccess() || ['*'] === $this->allowedMethods) {
if ($this->isSuccess() || $this->allowedMethods === Route::HTTP_METHOD_ANY) {
return false;
}

Expand All @@ -190,9 +183,9 @@ public function isMethodFailure() : bool
/**
* Retrieve the allowed methods for the route failure.
*
* @return string[] HTTP methods allowed
* @return null|string[] HTTP methods allowed
*/
public function getAllowedMethods() : array
public function getAllowedMethods() : ?array
{
if ($this->isSuccess()) {
return $this->route
Expand Down
4 changes: 2 additions & 2 deletions test/RouteResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testRouteNameIsNotRetrievable()
public function testRouteFailureRetrieveAllHttpMethods()
{
$result = RouteResult::fromRouteFailure(Route::HTTP_METHOD_ANY);
$this->assertSame(['*'], $result->getAllowedMethods());
$this->assertSame(Route::HTTP_METHOD_ANY, $result->getAllowedMethods());
}

public function testRouteFailureRetrieveHttpMethods()
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testFailureResultDoesNotIndicateAMethodFailureIfAllMethodsAreAll
public function testAllowedMethodsIncludesASingleWildcardEntryWhenAllMethodsAllowedForFailureResult(
RouteResult $result
) {
$this->assertSame(['*'], $result->getAllowedMethods());
$this->assertSame(Route::HTTP_METHOD_ANY, $result->getAllowedMethods());
}

public function testFailureResultProcessedAsMiddlewareDelegatesToHandler()
Expand Down