Skip to content

Commit 04e3e83

Browse files
authored
Make StreamWrapper::stream_stat() returns false if inner stream's size is null (#594)
1 parent 5b4d5ac commit 04e3e83

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/StreamWrapper.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,14 @@ public function stream_cast(int $cast_as)
136136
* ctime: int,
137137
* blksize: int,
138138
* blocks: int
139-
* }
139+
* }|false
140140
*/
141-
public function stream_stat(): array
141+
public function stream_stat()
142142
{
143+
if ($this->stream->getSize() === null) {
144+
return false;
145+
}
146+
143147
static $modeMap = [
144148
'r' => 33060,
145149
'rb' => 33060,

tests/StreamWrapperTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GuzzleHttp\Psr7;
88
use GuzzleHttp\Psr7\StreamWrapper;
9+
use GuzzleHttp\Psr7\Utils;
910
use PHPUnit\Framework\TestCase;
1011
use Psr\Http\Message\StreamInterface;
1112

@@ -187,4 +188,15 @@ public function testXmlWriterWithStream(): void
187188
$stream->rewind();
188189
self::assertXmlStringEqualsXmlString('<?xml version="1.0"?><foo />', (string) $stream);
189190
}
191+
192+
public function testWrappedNullSizedStreamStaysNullSized(): void
193+
{
194+
$nullSizedStream = new Psr7\PumpStream(function () { return ''; });
195+
$this->assertNull($nullSizedStream->getSize());
196+
197+
$resource = StreamWrapper::getResource($nullSizedStream);
198+
$stream = Utils::streamFor($resource);
199+
200+
$this->assertNull($stream->getSize());
201+
}
190202
}

0 commit comments

Comments
 (0)