/**
* @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');
}