/** * @todo Remove for 2.0.0; $err goes away in that version. * @group error-handling * @dataProvider nonNullNonThrowableNonStringErrors */ public function testEnablingRaiseThrowablesFlagWillCauseInvocationToRaiseMiddlewareExceptionForNonNullArguments($error) { $next = new Next($this->queue, $this->prophesize(DelegateInterface::class)->reveal()); $next->raiseThrowables(); $triggered = false; $this->errorHandler = set_error_handler(function ($errno, $errstr) use(&$triggered) { $this->assertContains('error middleware is deprecated', $errstr); $triggered = true; return true; }, E_USER_DEPRECATED); switch (true) { case is_object($error): $expected = get_class($error); break; case is_array($error): $expected = gettype($error); break; case is_scalar($error): // fall-through // fall-through default: $expected = var_export($error, true); break; } try { $next($this->request, $this->response, $error); $this->fail('Throwable not raised when it was expected'); } catch (Exception\MiddlewareException $e) { $this->assertContains($expected, $e->getMessage()); } catch (\Throwable $e) { $this->fail(sprintf('Caught unexpected throwable: %s', $e->getMessage())); } catch (\Exception $e) { $this->fail(sprintf('Caught unexpected exception: %s', $e->getMessage())); } $this->assertTrue($triggered, 'Deprecation notice not triggered'); }
/** * http-interop invocation: single-pass with delegate. * * Executes the internal pipeline, passing $delegate as the "final * handler" in cases when the pipeline exhausts itself. * * @param Request $request * @param DelegateInterface $delegate * @return Response */ public function process(Request $request, DelegateInterface $delegate) { $response = $this->responsePrototype; $next = new Next($this->pipeline, $delegate); if ($response) { $next->setResponsePrototype($response); } if ($this->raiseThrowables) { $next->raiseThrowables(); } $result = $next->process($request); return $result instanceof Response ? $result : $response; }