diff --git a/CHANGELOG.md b/CHANGELOG.md index d3eb840..e8e5f53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.13.0] - tomorrow + +- Added `Formatter::formatResponseForRequest()` +- Deprecated `Formatter::formatResponse()` + ## [1.12.0] - 2021-08-29 - Added support for adjusting binary detection regex in FullHttpMessageFormatter diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index f847a6b..0ee2b98 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -54,9 +54,10 @@ function it_formats_post_request(RequestInterface $request, UriInterface $uri, S $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --http2 --request POST --data 'body \" data test'\'' bar'"); } - function it_does_nothing_for_response(ResponseInterface $response) + function it_does_nothing_for_response(ResponseInterface $response, RequestInterface $request) { $this->formatResponse($response)->shouldReturn(''); + $this->formatResponseForRequest($response, $request)->shouldReturn(''); } function it_formats_the_request_with_user_agent(RequestInterface $request, UriInterface $uri, StreamInterface $body) diff --git a/spec/Formatter/FullHttpMessageFormatterSpec.php b/spec/Formatter/FullHttpMessageFormatterSpec.php index e89b7f2..33f83f6 100644 --- a/spec/Formatter/FullHttpMessageFormatterSpec.php +++ b/spec/Formatter/FullHttpMessageFormatterSpec.php @@ -126,7 +126,7 @@ function it_does_not_format_no_seekable_request(RequestInterface $request, Strea $this->formatRequest($request)->shouldReturn($expectedMessage); } - function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream) + function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream, RequestInterface $request) { $this->beConstructedWith(18); @@ -150,6 +150,7 @@ function it_formats_the_response_with_size_limit(ResponseInterface $response, St This is an HTML st STR; $this->formatResponse($response)->shouldReturn($expectedMessage); + $this->formatResponseForRequest($response, $request)->shouldReturn($expectedMessage); } function it_formats_the_response_without_size_limit(ResponseInterface $response, StreamInterface $stream) diff --git a/spec/Formatter/SimpleFormatterSpec.php b/spec/Formatter/SimpleFormatterSpec.php index ef70eb8..9c44d67 100644 --- a/spec/Formatter/SimpleFormatterSpec.php +++ b/spec/Formatter/SimpleFormatterSpec.php @@ -29,12 +29,13 @@ function it_formats_the_request(RequestInterface $request, UriInterface $uri) $this->formatRequest($request)->shouldReturn('GET http://foo.com/bar 1.1'); } - function it_formats_the_response(ResponseInterface $response) + function it_formats_the_response(ResponseInterface $response, RequestInterface $request) { $response->getReasonPhrase()->willReturn('OK'); $response->getProtocolVersion()->willReturn('1.1'); $response->getStatusCode()->willReturn('200'); $this->formatResponse($response)->shouldReturn('200 OK 1.1'); + $this->formatResponseForRequest($response, $request)->shouldReturn('200 OK 1.1'); } } diff --git a/src/Formatter.php b/src/Formatter.php index d6cd21b..b8cf7b4 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -9,6 +9,8 @@ * Formats a request and/or a response as a string. * * @author Márk Sági-Kazár + * + * @method string formatResponseForRequest(ResponseInterface $response, RequestInterface $request) Formats a response in context of its request. */ interface Formatter { @@ -20,6 +22,8 @@ interface Formatter public function formatRequest(RequestInterface $request); /** + * @deprecated since 1.13, use formatResponseForRequest() instead + * * Formats a response. * * @return string diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 78b1d55..31f5e7b 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -68,6 +68,14 @@ public function formatResponse(ResponseInterface $response) return ''; } + /** + * {@inheritdoc} + */ + public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) + { + return $this->formatResponse($response); + } + /** * @return string */ diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index bb22efe..451f667 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -74,6 +74,14 @@ public function formatResponse(ResponseInterface $response) return $this->addBody($response, $message); } + /** + * {@inheritdoc} + */ + public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) + { + return $this->formatResponse($response); + } + /** * Add the message body if the stream is seekable. * diff --git a/src/Formatter/SimpleFormatter.php b/src/Formatter/SimpleFormatter.php index b1fcabd..cfdfef9 100644 --- a/src/Formatter/SimpleFormatter.php +++ b/src/Formatter/SimpleFormatter.php @@ -39,4 +39,12 @@ public function formatResponse(ResponseInterface $response) $response->getProtocolVersion() ); } + + /** + * {@inheritdoc} + */ + public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) + { + return $this->formatResponse($response); + } }