/**
* @todo Remove for 2.0.0, as error middleware is removed in that version.
* @group error-handling
*/
public function testEnablingRaiseThrowablesCausesProcessToThrowExceptions()
{
$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 = $this->prophesize(DelegateInterface::class);
$done->process(Argument::any())->shouldNotBeCalled();
try {
$pipeline->process($this->request, $done->reveal());
$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()));
}
}