Skip to content

Commit 0d8df2b

Browse files
authored
Merge pull request #146 from ro0NL/req-resp
Add Formatter::formatResponseForRequest()
2 parents 10454be + b46b1b1 commit 0d8df2b

8 files changed

+39
-3
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
77
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

9+
## [1.13.0] - tomorrow
10+
11+
- Added `Formatter::formatResponseForRequest()`
12+
- Deprecated `Formatter::formatResponse()`
13+
914
## [1.12.0] - 2021-08-29
1015

1116
- Added support for adjusting binary detection regex in FullHttpMessageFormatter

Diff for: spec/Formatter/CurlCommandFormatterSpec.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ function it_formats_post_request(RequestInterface $request, UriInterface $uri, S
5454
$this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --http2 --request POST --data 'body \" data test'\'' bar'");
5555
}
5656

57-
function it_does_nothing_for_response(ResponseInterface $response)
57+
function it_does_nothing_for_response(ResponseInterface $response, RequestInterface $request)
5858
{
5959
$this->formatResponse($response)->shouldReturn('');
60+
$this->formatResponseForRequest($response, $request)->shouldReturn('');
6061
}
6162

6263
function it_formats_the_request_with_user_agent(RequestInterface $request, UriInterface $uri, StreamInterface $body)

Diff for: spec/Formatter/FullHttpMessageFormatterSpec.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function it_does_not_format_no_seekable_request(RequestInterface $request, Strea
126126
$this->formatRequest($request)->shouldReturn($expectedMessage);
127127
}
128128

129-
function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream)
129+
function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream, RequestInterface $request)
130130
{
131131
$this->beConstructedWith(18);
132132

@@ -150,6 +150,7 @@ function it_formats_the_response_with_size_limit(ResponseInterface $response, St
150150
This is an HTML st
151151
STR;
152152
$this->formatResponse($response)->shouldReturn($expectedMessage);
153+
$this->formatResponseForRequest($response, $request)->shouldReturn($expectedMessage);
153154
}
154155

155156
function it_formats_the_response_without_size_limit(ResponseInterface $response, StreamInterface $stream)

Diff for: spec/Formatter/SimpleFormatterSpec.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ function it_formats_the_request(RequestInterface $request, UriInterface $uri)
2929
$this->formatRequest($request)->shouldReturn('GET http://foo.com/bar 1.1');
3030
}
3131

32-
function it_formats_the_response(ResponseInterface $response)
32+
function it_formats_the_response(ResponseInterface $response, RequestInterface $request)
3333
{
3434
$response->getReasonPhrase()->willReturn('OK');
3535
$response->getProtocolVersion()->willReturn('1.1');
3636
$response->getStatusCode()->willReturn('200');
3737

3838
$this->formatResponse($response)->shouldReturn('200 OK 1.1');
39+
$this->formatResponseForRequest($response, $request)->shouldReturn('200 OK 1.1');
3940
}
4041
}

Diff for: src/Formatter.php

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* Formats a request and/or a response as a string.
1010
*
1111
* @author Márk Sági-Kazár <[email protected]>
12+
*
13+
* @method string formatResponseForRequest(ResponseInterface $response, RequestInterface $request) Formats a response in context of its request.
1214
*/
1315
interface Formatter
1416
{
@@ -20,6 +22,8 @@ interface Formatter
2022
public function formatRequest(RequestInterface $request);
2123

2224
/**
25+
* @deprecated since 1.13, use formatResponseForRequest() instead
26+
*
2327
* Formats a response.
2428
*
2529
* @return string

Diff for: src/Formatter/CurlCommandFormatter.php

+8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ public function formatResponse(ResponseInterface $response)
6868
return '';
6969
}
7070

71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request)
75+
{
76+
return $this->formatResponse($response);
77+
}
78+
7179
/**
7280
* @return string
7381
*/

Diff for: src/Formatter/FullHttpMessageFormatter.php

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public function formatResponse(ResponseInterface $response)
7474
return $this->addBody($response, $message);
7575
}
7676

77+
/**
78+
* {@inheritdoc}
79+
*/
80+
public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request)
81+
{
82+
return $this->formatResponse($response);
83+
}
84+
7785
/**
7886
* Add the message body if the stream is seekable.
7987
*

Diff for: src/Formatter/SimpleFormatter.php

+8
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ public function formatResponse(ResponseInterface $response)
3939
$response->getProtocolVersion()
4040
);
4141
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request)
47+
{
48+
return $this->formatResponse($response);
49+
}
4250
}

0 commit comments

Comments
 (0)