Skip to content

Commit

Permalink
Add tests for emit different stream types
Browse files Browse the repository at this point in the history
  • Loading branch information
mapogolions committed Aug 15, 2019
1 parent b68b1fd commit d10ac81
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions tests/ResponseEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testRespond()
$this->expectOutputString('Hello');
}

public function testRespondNoContent()
public function testResposeWithNoContentSkipsContentTypeAndContentLength()
{
$response = $this
->createResponse()
Expand All @@ -55,7 +55,7 @@ public function testRespondNoContent()
$this->expectOutputString('');
}

public function testNonEmptyResponse()
public function testNonEmptyResponseDoesNotSkipContentTypeAndContentLength()
{
$response = $this
->createResponse()
Expand Down Expand Up @@ -197,7 +197,34 @@ public function testIsResponseEmptyWithNonEmptyBodyAndTriggeringStatusCode()
$this->assertTrue($responseEmitter->isResponseEmpty($response));
}

public function testAvoidReadFromSlowStreamAccordingStatus()
public function testIsResponseEmptyDoesNotReadAllDataFromNonEmptySeekableResponse()
{
$body = $this->createStream('Hello');
$response = $this
->createResponse(200)
->withBody($body);
$responseEmitter = new ResponseEmitter();

$responseEmitter->isResponseEmpty($response);

$this->assertTrue($body->isSeekable());
$this->assertFalse($body->eof());
}

public function testIsResponseEmptyDoesNotDrainNonSeekableResponseWithContent()
{
$resource = popen('echo 12', 'r');
$body = $this->getStreamFactory()->createStreamFromResource($resource);
$response = $this->createResponse(200)->withBody($body);
$responseEmitter = new ResponseEmitter();

$responseEmitter->isResponseEmpty($response);

$this->assertFalse($body->isSeekable());
$this->assertSame('12', trim((string) $body));
}

public function testAvoidReadFromSlowStreamAccordingToStatus()
{
$body = new SlowPokeStream();
$response = $this
Expand Down

0 comments on commit d10ac81

Please sign in to comment.