File tree 3 files changed +25
-1
lines changed
3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,7 @@ public function withBody(StreamInterface $body): self
186
186
$ new ->dataStream = $ body ;
187
187
$ new ->forcedBody = true ;
188
188
$ new ->formatted = false ;
189
+ $ new ->data = null ;
189
190
return $ new ;
190
191
}
191
192
Original file line number Diff line number Diff line change @@ -241,6 +241,29 @@ public function testWithBody(): void
241
241
$ this ->assertSame ('test2 ' , $ dataResponse ->getBody ()->getContents ());
242
242
}
243
243
244
+ public function testWithBodyAndWithResponseFormatter (): void
245
+ {
246
+ $ dataResponse = $ this ->createDataResponse ('test1 ' )
247
+ ->withResponseFormatter (new JsonDataResponseFormatter ())
248
+ ->withBody ($ this ->createStream ('test2 ' ))
249
+ ;
250
+
251
+ $ dataResponse ->getBody ()->rewind ();
252
+
253
+ $ this ->assertSame (['application/json; charset=UTF-8 ' ], $ dataResponse ->getHeader (Header::CONTENT_TYPE ));
254
+ $ this ->assertSame ('test2 ' , $ dataResponse ->getBody ()->getContents ());
255
+
256
+ $ dataResponse = $ dataResponse
257
+ ->withBody ($ this ->createStream ('test3 ' ))
258
+ ->withResponseFormatter (new XmlDataResponseFormatter ())
259
+ ;
260
+
261
+ $ dataResponse ->getBody ()->rewind ();
262
+
263
+ $ this ->assertSame (['application/xml; charset=UTF-8 ' ], $ dataResponse ->getHeader (Header::CONTENT_TYPE ));
264
+ $ this ->assertSame ('test3 ' , $ dataResponse ->getBody ()->getContents ());
265
+ }
266
+
244
267
public function testWithBodyIfDataIsNull (): void
245
268
{
246
269
$ dataResponse = $ this ->createDataResponse (null )->withBody ($ this ->createStream ('test ' ));
Original file line number Diff line number Diff line change 9
9
use Yiisoft \DataResponse \DataResponse ;
10
10
use Yiisoft \DataResponse \DataResponseFormatterInterface ;
11
11
12
- class CustomDataResponseFormatter implements DataResponseFormatterInterface
12
+ final class CustomDataResponseFormatter implements DataResponseFormatterInterface
13
13
{
14
14
private int $ statusCode = 200 ;
15
15
private array $ headers = [];
You can’t perform that action at this time.
0 commit comments