Skip to content

Commit 98de591

Browse files
authored
Raise percentage of mutation score indicator (#59)
1 parent 22d7076 commit 98de591

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

tests/DataResponseTest.php

+47-10
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ public function testWithoutHeader(): void
192192
public function testWithHeader(): void
193193
{
194194
$dataResponse = $this->createDataResponseFactory()->createResponse()
195-
->withHeader(Header::CONTENT_TYPE, 'application/json');
195+
->withHeader(Header::CONTENT_TYPE, 'application/json')
196+
;
196197

197198
$this->assertSame(['Content-Type' => ['application/json']], $dataResponse->getHeaders());
198199
}
@@ -201,7 +202,8 @@ public function testWithAddedHeader(): void
201202
{
202203
$dataResponse = $this->createDataResponseFactory()->createResponse()
203204
->withHeader(Header::CONTENT_TYPE, 'application/json')
204-
->withAddedHeader(Header::CONTENT_TYPE, 'application/xml');
205+
->withAddedHeader(Header::CONTENT_TYPE, 'application/xml')
206+
;
205207

206208
$this->assertSame(['Content-Type' => ['application/json', 'application/xml']], $dataResponse->getHeaders());
207209
}
@@ -294,6 +296,24 @@ public function testWithData(): void
294296
$this->assertSame('test2', $dataResponse->getBody()->getContents());
295297
}
296298

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+
297317
public function testWithDataThrowsExceptionIfWithBodyWasCalled(): void
298318
{
299319
$dataResponse = $this->createDataResponse('test1');
@@ -382,32 +402,49 @@ public function testImmutability(): void
382402
public function testFormatterCouldChangeStatusCode(): void
383403
{
384404
$formatter = (new CustomDataResponseFormatter())->withStatusCode(410);
385-
$dataResponse = $this->createDataResponse(['test'])->withResponseFormatter($formatter);
405+
$dataResponse = $this->createDataResponse(['test'])->withResponseFormatter($formatter)->withStatus(200);
386406

387-
$this->assertEquals(410, $dataResponse->getStatusCode());
407+
$this->assertSame(410, $dataResponse->getStatusCode());
388408
}
389409

390410
public function testFormatterCouldChangeHeaders(): void
391411
{
392412
$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+
;
394416

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'));
396429
}
397430

398431
public function testFormatterCouldChangeProtocol(): void
399432
{
400433
$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+
;
402437

403-
$this->assertEquals('2.0', $dataResponse->getProtocolVersion());
438+
$this->assertSame('2.0', $dataResponse->getProtocolVersion());
404439
}
405440

406441
public function testFormatterCouldChangeReasonPhrase(): void
407442
{
408443
$formatter = (new CustomDataResponseFormatter())->withReasonPhrase('Reason');
409-
$dataResponse = $this->createDataResponse(['test'])->withResponseFormatter($formatter);
444+
$dataResponse = $this->createDataResponse(['test'])->withResponseFormatter($formatter)
445+
->withStatus(200, 'OK')
446+
;
410447

411-
$this->assertEquals('Reason', $dataResponse->getReasonPhrase());
448+
$this->assertSame('Reason', $dataResponse->getReasonPhrase());
412449
}
413450
}

0 commit comments

Comments
 (0)