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

Commit

Permalink
Merge branch 'hotfix/32-route-result-failure-arguments' into release-…
Browse files Browse the repository at this point in the history
…3.0.0

Close #32
  • Loading branch information
weierophinney committed Dec 7, 2017
2 parents 4f3dba2 + 89633bd commit 1234ab0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ZendRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private function marshalSuccessResultFromRouteMatch(RouteMatch $match, PsrReques
// This should never happen, as Zend\Expressive\Router\Route always
// ensures a non-empty route name. Marking as failed route to be
// consistent with other implementations.
return RouteResult::fromRouteFailure();
return RouteResult::fromRouteFailure(Route::HTTP_METHOD_ANY);
}

return RouteResult::fromRoute($route, $params);
Expand Down
22 changes: 22 additions & 0 deletions test/ZendRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Zend\Expressive\Router\ZendRouter;
use Zend\Http\Request as ZendRequest;
use Zend\I18n\Translator\TranslatorInterface;
use Zend\Psr7Bridge\Psr7ServerRequest;
use Zend\Router\Http\TreeRouteStack;
use Zend\Router\RouteMatch;

Expand Down Expand Up @@ -266,6 +267,27 @@ public function testMatch()
$this->assertEquals($middleware, $result->getMatchedMiddleware());
}

public function testReturnsRouteFailureForRouteInjectedManuallyIntoBaseRouterButNotRouterBridge()
{
$uri = $this->prophesize(UriInterface::class);
$uri->getPath()->willReturn('/foo');

$request = new ServerRequest(['REQUEST_METHOD' => 'GET'], [], '/foo', 'GET');
$zendRequest = Psr7ServerRequest::toZend($request);

$routeMatch = new \Zend\Router\Http\RouteMatch([], 4);
$routeMatch->setMatchedRouteName('/foo');

$this->zendRouter->match($zendRequest)->willReturn($routeMatch);

$router = $this->getRouter();
$result = $router->match($request);

$this->assertInstanceOf(RouteResult::class, $result);
$this->assertTrue($result->isFailure());
$this->assertFalse($result->isMethodFailure());
}

public function testMatchedRouteNameNoAllowedMethods()
{
$middleware = $this->getMiddleware();
Expand Down

0 comments on commit 1234ab0

Please sign in to comment.