diff --git a/src/CachingStream.php b/src/CachingStream.php index fe749e98..febade9f 100644 --- a/src/CachingStream.php +++ b/src/CachingStream.php @@ -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() diff --git a/tests/CachingStreamTest.php b/tests/CachingStreamTest.php index c760f5db..a1fa04ae 100644 --- a/tests/CachingStreamTest.php +++ b/tests/CachingStreamTest.php @@ -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);