Skip to content

Commit

Permalink
Make StreamWrapper::stream_stat() returns false if inner stream's…
Browse files Browse the repository at this point in the history
… size is `null` (#594)
  • Loading branch information
chapa committed Jul 18, 2024
1 parent 5b4d5ac commit 04e3e83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,14 @@ public function stream_cast(int $cast_as)
* ctime: int,
* blksize: int,
* blocks: int
* }
* }|false
*/
public function stream_stat(): array
public function stream_stat()
{
if ($this->stream->getSize() === null) {
return false;
}

static $modeMap = [
'r' => 33060,
'rb' => 33060,
Expand Down
12 changes: 12 additions & 0 deletions tests/StreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\StreamWrapper;
use GuzzleHttp\Psr7\Utils;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamInterface;

Expand Down Expand Up @@ -187,4 +188,15 @@ public function testXmlWriterWithStream(): void
$stream->rewind();
self::assertXmlStringEqualsXmlString('<?xml version="1.0"?><foo />', (string) $stream);
}

public function testWrappedNullSizedStreamStaysNullSized(): void
{
$nullSizedStream = new Psr7\PumpStream(function () { return ''; });
$this->assertNull($nullSizedStream->getSize());

$resource = StreamWrapper::getResource($nullSizedStream);
$stream = Utils::streamFor($resource);

$this->assertNull($stream->getSize());
}
}

0 comments on commit 04e3e83

Please sign in to comment.