Skip to content

Commit

Permalink
Fixing return of values seen as empty in Response.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Oct 18, 2016
1 parent 605f350 commit 0c0f32f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Network/Response.php
Expand Up @@ -438,7 +438,7 @@ public function __construct(array $options = [])
}
if (isset($options['stream'])) {
if (!$options['stream'] instanceof StreamInterface) {
throw new InvalidArgumentException('Stream option must be an object implement StreamInterface');
throw new InvalidArgumentException('Stream option must be an object that implements StreamInterface');
}
$this->stream = $options['stream'];
} else {
Expand Down Expand Up @@ -741,7 +741,7 @@ public function body($content = null)
if ($content === null) {
$this->stream->rewind();
$result = $this->stream->getContents();
if (empty($result)) {
if (empty($result) && strlen($result) === 0) {
return null;
}

Expand All @@ -758,7 +758,7 @@ public function body($content = null)
$this->stream->rewind();
$result = $this->stream->getContents();

if (empty($result)) {
if (empty($result) && strlen($result) === 0) {
return null;
}

Expand Down Expand Up @@ -1108,6 +1108,7 @@ public function sharable($public = null, $time = null)

/**
* Sets the Cache-Control s-maxage directive.
*
* The max-age is the number of seconds after which the response should no longer be considered
* a good candidate to be fetched from a shared cache (like in a proxy server).
* If called with no parameters, this function will return the current max-age value if any
Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/Network/ResponseTest.php
Expand Up @@ -99,6 +99,18 @@ public function testBody()
$response->body('Response body');
$this->assertEquals('Response body', $response->body());
$this->assertEquals('Changed Body', $response->body('Changed Body'));

$response = new Response();
$response->body(0);
$this->assertEquals(0, $response->body());

$response = new Response();
$response->body('0');
$this->assertEquals('0', $response->body());

$response = new Response();
$response->body(null);
$this->assertEquals(null, $response->body());
}

/**
Expand Down

0 comments on commit 0c0f32f

Please sign in to comment.