This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Ensure all paths for route result generation are tested #28
Closed
weierophinney
wants to merge
1
commit into
zendframework:release-3.0.0
from
weierophinney:hotfix/route-result-failure-args
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will remove on merge; nice catch! |
||
$router = $this->getRouter(); | ||
|
||
$result = $router->match($request->reveal()); | ||
|
||
$this->assertInstanceOf(RouteResult::class, $result); | ||
$this->assertTrue($result->isFailure()); | ||
$this->assertFalse($result->isMethodFailure()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we have
$request->reveal()
here?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.
Yes... which is odd, as that should not work correctly otherwise...
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.
Please see my PR:
https://github.com/zendframework/zend-expressive-zendrouter/pull/32/files
I'm not mocking the request, maybe you should do the same here?