-
Notifications
You must be signed in to change notification settings - Fork 56
Ensure that MiddlewarePipes are called as callables if an error is present #95
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,6 +441,99 @@ public function testInvokingWithInteropMiddlewareDispatchesIt() | |
); | ||
} | ||
|
||
/** | ||
* @todo Remove this test for version 2.0 | ||
*/ | ||
public function testInvokingWithMiddlewarePipeAndErrorDispatchesNextErrorMiddleware() | ||
{ | ||
$error = new RuntimeException('expected'); | ||
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. Consider using just 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. I'll rewrite to use a data provider to seed multiple exception/throwable types. Thanks for the feedback! |
||
$request = $this->prophesize(ServerRequestInterface::class)->reveal(); | ||
$response = $this->prophesize(ResponseInterface::class)->reveal(); | ||
$expected = $this->prophesize(ResponseInterface::class)->reveal(); | ||
|
||
$next = $this->prophesize(Next::class); | ||
$next->willImplement(DelegateInterface::class); | ||
$next | ||
->__invoke( | ||
$request, | ||
$this->response->reveal(), | ||
$error | ||
) | ||
->willReturn($expected); | ||
|
||
$middleware = $this->prophesize(MiddlewarePipe::class); | ||
$middleware | ||
->__invoke( | ||
Argument::type(ServerRequestInterface::class), | ||
Argument::type(ResponseInterface::class), | ||
Argument::type('callable') | ||
) | ||
->shouldNotBeCalled(); | ||
$middleware | ||
->process( | ||
Argument::type(ServerRequestInterface::class), | ||
Argument::type(DelegateInterface::class) | ||
) | ||
->shouldNotBeCalled(); | ||
|
||
$route = new Route('/foo', $middleware->reveal()); | ||
|
||
$dispatch = new Dispatch(); | ||
|
||
$this->assertSame( | ||
$expected, | ||
$dispatch($route, $error, $request, $this->response->reveal(), $next->reveal()) | ||
); | ||
} | ||
|
||
/** | ||
* @todo Remove this test for version 2.0 | ||
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. Should probably spawn an issue for 2.0 for this, then link the issue instead 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. See note above; I'll just remove these, as there's a note at the top of this file already. |
||
*/ | ||
public function testInvokingWithMiddlewarePipeAndNoErrorDispatchesAsInteropMiddleware() | ||
{ | ||
$request = $this->prophesize(ServerRequestInterface::class)->reveal(); | ||
$response = $this->prophesize(ResponseInterface::class)->reveal(); | ||
|
||
$next = $this->prophesize(Next::class); | ||
$next->willImplement(DelegateInterface::class); | ||
$next | ||
->__invoke( | ||
Argument::type(ServerRequestInterface::class), | ||
Argument::type(ResponseInterface::class) | ||
) | ||
->shouldNotBeCalled(); | ||
$next | ||
->process(Argument::type(ServerRequestInterface::class)) | ||
->shouldNotBeCalled(); | ||
|
||
$middleware = $this->prophesize(MiddlewarePipe::class); | ||
$middleware | ||
->__invoke( | ||
Argument::type(ServerRequestInterface::class), | ||
Argument::type(ResponseInterface::class), | ||
Argument::type('callable') | ||
) | ||
->shouldNotBeCalled(); | ||
$middleware | ||
->hasResponsePrototype() | ||
->willReturn(true); | ||
$middleware | ||
->process( | ||
Argument::type(ServerRequestInterface::class), | ||
Argument::type(DelegateInterface::class) | ||
) | ||
->willReturn($response); | ||
|
||
$route = new Route('/foo', $middleware->reveal()); | ||
|
||
$dispatch = new Dispatch(); | ||
|
||
$this->assertSame( | ||
$response, | ||
$dispatch($route, null, $request, $this->response->reveal(), $next->reveal()) | ||
); | ||
} | ||
|
||
/** | ||
* @group http-interop | ||
*/ | ||
|
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 probably spawn an issue for 2.0 for this, then link the issue instead
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: why is this not needed in 2.0?
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.
Because this class goes away entirely, and that version will only work with http-interop middleware. 😉
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.
Which means, really, that this
@todo
can go away, as the top of the classfile already indicates the entire file goes away. Updating...