@@ -192,7 +192,8 @@ public function testWithoutHeader(): void
192
192
public function testWithHeader (): void
193
193
{
194
194
$ dataResponse = $ this ->createDataResponseFactory ()->createResponse ()
195
- ->withHeader (Header::CONTENT_TYPE , 'application/json ' );
195
+ ->withHeader (Header::CONTENT_TYPE , 'application/json ' )
196
+ ;
196
197
197
198
$ this ->assertSame (['Content-Type ' => ['application/json ' ]], $ dataResponse ->getHeaders ());
198
199
}
@@ -201,7 +202,8 @@ public function testWithAddedHeader(): void
201
202
{
202
203
$ dataResponse = $ this ->createDataResponseFactory ()->createResponse ()
203
204
->withHeader (Header::CONTENT_TYPE , 'application/json ' )
204
- ->withAddedHeader (Header::CONTENT_TYPE , 'application/xml ' );
205
+ ->withAddedHeader (Header::CONTENT_TYPE , 'application/xml ' )
206
+ ;
205
207
206
208
$ this ->assertSame (['Content-Type ' => ['application/json ' , 'application/xml ' ]], $ dataResponse ->getHeaders ());
207
209
}
@@ -294,6 +296,24 @@ public function testWithData(): void
294
296
$ this ->assertSame ('test2 ' , $ dataResponse ->getBody ()->getContents ());
295
297
}
296
298
299
+ public function testWithDataMultipleCalls (): void
300
+ {
301
+ $ dataResponse = $ this ->createDataResponse ('test1 ' );
302
+ $ dataResponse ->getBody ()->rewind ();
303
+
304
+ $ dataResponse = $ dataResponse ->withData ('test2 ' );
305
+ $ this ->assertSame (5 , $ dataResponse ->getBody ()->tell ());
306
+ $ dataResponse ->getBody ()->rewind ();
307
+
308
+ $ this ->assertSame ('test2 ' , $ dataResponse ->getBody ()->getContents ());
309
+
310
+ $ dataResponse = $ dataResponse ->withData ('test3 ' );
311
+ $ this ->assertSame (5 , $ dataResponse ->getBody ()->tell ());
312
+ $ dataResponse ->getBody ()->rewind ();
313
+
314
+ $ this ->assertSame ('test3 ' , $ dataResponse ->getBody ()->getContents ());
315
+ }
316
+
297
317
public function testWithDataThrowsExceptionIfWithBodyWasCalled (): void
298
318
{
299
319
$ dataResponse = $ this ->createDataResponse ('test1 ' );
@@ -382,32 +402,49 @@ public function testImmutability(): void
382
402
public function testFormatterCouldChangeStatusCode (): void
383
403
{
384
404
$ formatter = (new CustomDataResponseFormatter ())->withStatusCode (410 );
385
- $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter );
405
+ $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter )-> withStatus ( 200 ) ;
386
406
387
- $ this ->assertEquals (410 , $ dataResponse ->getStatusCode ());
407
+ $ this ->assertSame (410 , $ dataResponse ->getStatusCode ());
388
408
}
389
409
390
410
public function testFormatterCouldChangeHeaders (): void
391
411
{
392
412
$ formatter = (new CustomDataResponseFormatter ())->withHeaders (['Content-Type ' => 'Custom ' ]);
393
- $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter );
413
+ $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter )
414
+ ->withHeader ('Content-Type ' , 'plain/text ' )
415
+ ;
394
416
395
- $ this ->assertEquals ('Custom ' , $ dataResponse ->getHeaderLine ('Content-Type ' ));
417
+ $ this ->assertSame ('Custom ' , $ dataResponse ->getHeaderLine ('Content-Type ' ));
418
+ }
419
+
420
+ public function testFormatterCouldChangeAndAddHeaders (): void
421
+ {
422
+ $ formatter = (new CustomDataResponseFormatter ())->withHeaders (['Content-Type ' => 'Custom ' ]);
423
+ $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter )
424
+ ->withHeader ('Content-Type ' , 'plain/text ' )
425
+ ->withAddedHeader ('Content-Type ' , 'plain/html ' )
426
+ ;
427
+
428
+ $ this ->assertSame ('Custom ' , $ dataResponse ->getHeaderLine ('Content-Type ' ));
396
429
}
397
430
398
431
public function testFormatterCouldChangeProtocol (): void
399
432
{
400
433
$ formatter = (new CustomDataResponseFormatter ())->withProtocol ('2.0 ' );
401
- $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter );
434
+ $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter )
435
+ ->withProtocolVersion ('1.0 ' )
436
+ ;
402
437
403
- $ this ->assertEquals ('2.0 ' , $ dataResponse ->getProtocolVersion ());
438
+ $ this ->assertSame ('2.0 ' , $ dataResponse ->getProtocolVersion ());
404
439
}
405
440
406
441
public function testFormatterCouldChangeReasonPhrase (): void
407
442
{
408
443
$ formatter = (new CustomDataResponseFormatter ())->withReasonPhrase ('Reason ' );
409
- $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter );
444
+ $ dataResponse = $ this ->createDataResponse (['test ' ])->withResponseFormatter ($ formatter )
445
+ ->withStatus (200 , 'OK ' )
446
+ ;
410
447
411
- $ this ->assertEquals ('Reason ' , $ dataResponse ->getReasonPhrase ());
448
+ $ this ->assertSame ('Reason ' , $ dataResponse ->getReasonPhrase ());
412
449
}
413
450
}
0 commit comments