Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.6] Make StreamWrapper::stream_stat() returns false if inner stream's size is null #594

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}