Skip to content

Commit a0c4a5f

Browse files
Return null in caching stream size if remote is null (#438)
* Return null in caching stream size if remote is null * Added test coverage * Fixed typo * Fixes
1 parent 9d00674 commit a0c4a5f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/CachingStream.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ public function __construct(
3636

3737
public function getSize()
3838
{
39-
return max($this->stream->getSize(), $this->remoteStream->getSize());
39+
$remoteSize = $this->remoteStream->getSize();
40+
41+
if (null === $remoteSize) {
42+
return null;
43+
}
44+
45+
return max($this->stream->getSize(), $remoteSize);
4046
}
4147

4248
public function rewind()

tests/CachingStreamTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,22 @@ public function tearDownTest()
3434
$this->body->close();
3535
}
3636

37-
public function testUsesRemoteSizeIfPossible()
37+
public function testUsesRemoteSizeIfAvailable()
3838
{
3939
$body = Psr7\Utils::streamFor('test');
4040
$caching = new CachingStream($body);
4141
self::assertSame(4, $caching->getSize());
4242
}
4343

44+
public function testUsesRemoteSizeIfNotAvailable()
45+
{
46+
$body = new Psr7\PumpStream(function () {
47+
return 'a';
48+
});
49+
$caching = new CachingStream($body);
50+
self::assertNull($caching->getSize());
51+
}
52+
4453
public function testReadsUntilCachedToByte()
4554
{
4655
$this->body->seek(5);

0 commit comments

Comments
 (0)