Skip to content

Commit

Permalink
Merge pull request #449 from guzzle/merge-1.x
Browse files Browse the repository at this point in the history
Merge 1.x -> master
  • Loading branch information
Nyholm committed Oct 6, 2021
2 parents c793ad3 + 7a669b6 commit 6e68697
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
for backwards compatibility. Callers relying on the exception being thrown to detect invalid
URIs should catch the new exception.

### Fixed

- Return `null` in caching stream size if remote size is `null`

## 2.0.0 - 2021-06-30

Identical to the RC release.
Expand Down
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(): ?int
{
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(): void
Expand Down
11 changes: 10 additions & 1 deletion tests/CachingStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ protected function tearDown(): void
$this->body->close();
}

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

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

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

0 comments on commit 6e68697

Please sign in to comment.