Skip to content

Commit

Permalink
Return null in caching stream size if remote is null (#438)
Browse files Browse the repository at this point in the history
* Return null in caching stream size if remote is null

* Added test coverage

* Fixed typo

* Fixes
  • Loading branch information
GrahamCampbell authored Oct 4, 2021
1 parent 9d00674 commit a0c4a5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/CachingStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ public function __construct(

public function getSize()
{
return max($this->stream->getSize(), $this->remoteStream->getSize());
$remoteSize = $this->remoteStream->getSize();

if (null === $remoteSize) {
return null;
}

return max($this->stream->getSize(), $remoteSize);
}

public function rewind()
Expand Down
11 changes: 10 additions & 1 deletion tests/CachingStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ public function tearDownTest()
$this->body->close();
}

public function testUsesRemoteSizeIfPossible()
public function testUsesRemoteSizeIfAvailable()
{
$body = Psr7\Utils::streamFor('test');
$caching = new CachingStream($body);
self::assertSame(4, $caching->getSize());
}

public function testUsesRemoteSizeIfNotAvailable()
{
$body = new Psr7\PumpStream(function () {
return 'a';
});
$caching = new CachingStream($body);
self::assertNull($caching->getSize());
}

public function testReadsUntilCachedToByte()
{
$this->body->seek(5);
Expand Down

0 comments on commit a0c4a5f

Please sign in to comment.