From 26f6e28160ecedd4bb600bcb52cb28bbdfaebad0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 21 Mar 2019 12:59:19 +0100 Subject: [PATCH] [HttpClient] improve MockResponse --- .../HttpClient/Response/MockResponse.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Symfony/Component/HttpClient/Response/MockResponse.php b/src/Symfony/Component/HttpClient/Response/MockResponse.php index 4d0bc43ea4..c6630b65bc 100644 --- a/src/Symfony/Component/HttpClient/Response/MockResponse.php +++ b/src/Symfony/Component/HttpClient/Response/MockResponse.php @@ -27,6 +27,7 @@ class MockResponse implements ResponseInterface use ResponseTrait; private $body; + private $requestOptions = []; private static $mainMulti; private static $idSequence = 0; @@ -42,6 +43,28 @@ class MockResponse implements ResponseInterface { $this->body = \is_iterable($body) ? $body : (string) $body; $this->info = $info + $this->info; + + if (!isset($info['raw_headers'])) { + return; + } + + $rawHeaders = []; + + foreach ($info['raw_headers'] as $k => $v) { + foreach ((array) $v as $v) { + $rawHeaders[] = (\is_string($k) ? $k.': ' : '').$v; + } + } + + $info['raw_headers'] = $rawHeaders; + } + + /** + * Returns the options used when doing the request. + */ + public function getRequestOptions(): array + { + return $this->requestOptions; } /** @@ -66,6 +89,7 @@ class MockResponse implements ResponseInterface public static function fromRequest(string $method, string $url, array $options, ResponseInterface $mock): self { $response = new self([]); + $response->requestOptions = $options; $response->id = ++self::$idSequence; $response->content = ($options['buffer'] ?? true) ? fopen('php://temp', 'w+') : null; $response->initializer = static function (self $response) {