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

Commit

Permalink
Merge a028539 into b22b587
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Dec 7, 2017
2 parents b22b587 + a028539 commit 498c1ca
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/AuraRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private function marshalFailedRoute(
return RouteResult::fromRouteFailure(Route::HTTP_METHOD_ANY);
}

return RouteResult::fromRouteFailure();
return RouteResult::fromRouteFailure($failedRoute->allows ?: []);
}

/**
Expand All @@ -179,7 +179,7 @@ private function marshalMatchedRoute(AuraRoute $auraRoute) : RouteResult
$route = $this->matchAuraRouteToRoute($auraRoute);
if (! $route) {
// This should likely never occur, but is present for completeness.
return RouteResult::fromRouteFailure();
return RouteResult::fromRouteFailure(Route::HTTP_METHOD_ANY);
}

return RouteResult::fromRoute($route, $auraRoute->attributes);
Expand Down
53 changes: 53 additions & 0 deletions test/AuraRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,57 @@ public function testWhenRouteAllowsAnyHttpMethodRouterShouldResultInSuccess($met
$this->assertInstanceOf(RouteResult::class, $result);
$this->assertTrue($result->isSuccess(), 'Routing failed, but should have succeeded');
}

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

$request = $this->prophesize(ServerRequestInterface::class);
$request->getUri()->willReturn($uri);
$request->getMethod()->willReturn(RequestMethod::METHOD_GET);
$request->getServerParams()->willReturn([]);

// Not mocking the router container or Aura\Route; this particular test
// is testing how the parts integrate.
$router = new AuraRouter();
$router->addRoute(new Route('/foo', $this->getMiddleware(), []));

$result = $router->match($request->reveal());
$this->assertInstanceOf(RouteResult::class, $result);
$this->assertTrue($result->isFailure(), 'Routing did not fail, but should have');
$this->assertFalse($result->isMethodFailure(), 'Failure was due to HTTP method, but should NOT have been');
}

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

$request = $this->prophesize(ServerRequestInterface::class);
$request->getUri()->willReturn($uri);
$request->getMethod()->willReturn(RequestMethod::METHOD_GET);
$request->getServerParams()->willReturn([]);

$auraRoute = new AuraRoute();
$auraRoute->name('/foo');
$auraRoute->path('/foo');
$auraRoute->handler('foo');
$auraRoute->allows([RequestMethod::METHOD_GET]);
$auraRoute->attributes([
'action' => 'foo',
'bar' => 'baz',
]);

$this->auraMatcher->match($request)->willReturn($auraRoute);

$middleware = $this->getMiddleware();
$router = $this->getRouter();

$result = $router->match($request->reveal());

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

0 comments on commit 498c1ca

Please sign in to comment.