withHeader('User-Agent', drupal_generate_test_ua($test_prefix)); } return $handler($request, $options) ->then(function (ResponseInterface $response) use ($request) { if (!drupal_valid_test_ua()) { return $response; } $headers = $response->getHeaders(); foreach ($headers as $header_name => $header_values) { if (preg_match('/^X-Drupal-Assertion-[0-9]+$/', $header_name, $matches)) { foreach ($header_values as $header_value) { // Call \Drupal\simpletest\WebTestBase::error() with the parameters from // the header. $parameters = unserialize(urldecode($header_value)); if (count($parameters) === 3) { throw new \Exception($parameters[1] . ': ' . $parameters[0] . "\n" . Error::formatBacktrace([$parameters[2]])); } else { throw new \Exception('Error thrown with the wrong amount of parameters.'); } } } } return $response; }); }; }; } }