public function testEnablingRaiseThrowablesCausesInvocationToThrowExceptions()
{
$expected = new RuntimeException('To throw from middleware');
$pipeline = new MiddlewarePipe();
$pipeline->raiseThrowables();
$middleware = $this->prophesize(ServerMiddlewareInterface::class);
$middleware->process(Argument::type(ServerRequestInterface::class), Argument::type(DelegateInterface::class))->will(function () use($expected) {
throw $expected;
});
$pipeline->pipe($middleware->reveal());
$done = function ($request, $response) {
$this->fail('"Done" callable invoked, when it should have been');
};
try {
$pipeline($this->request, $this->response, $done);
$this->fail('Pipeline with middleware that throws did not result in exception!');
} catch (RuntimeException $e) {
$this->assertSame($expected, $e);
} catch (Throwable $e) {
$this->fail(sprintf('Unexpected throwable raised by pipeline: %s', $e->getMessage()));
} catch (\Exception $e) {
$this->fail(sprintf('Unexpected exception raised by pipeline: %s', $e->getMessage()));
}
}