Skip to content

Commit deda3d4

Browse files
committed
Fix incomplete StreamInterface implementation in PsrMessageStream
1 parent 5da55c8 commit deda3d4

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/Internal/PsrMessageStream.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ final class PsrMessageStream implements StreamInterface
1616

1717
private bool $isEof = false;
1818

19+
private bool $isClosed = false;
20+
1921
private int $position = 0;
2022

2123
public function __construct(private readonly ReadableStream $source, private readonly ?int $size = null)
@@ -32,6 +34,7 @@ public function close(): void
3234
$this->source->close();
3335
$this->buffer = '';
3436
$this->isEof = true;
37+
$this->isClosed = true;
3538
}
3639

3740
public function detach(): void
@@ -46,6 +49,10 @@ public function eof(): bool
4649

4750
public function getContents(): string
4851
{
52+
if ($this->isClosed) {
53+
throw new \RuntimeException("Stream is closed");
54+
}
55+
4956
$buffer = $this->buffer;
5057
$this->buffer = '';
5158

@@ -69,7 +76,7 @@ public function getSize(): ?int
6976

7077
public function isReadable(): bool
7178
{
72-
return !$this->eof();
79+
return !$this->isClosed;
7380
}
7481

7582
public function isSeekable(): bool
@@ -84,7 +91,7 @@ public function isWritable(): bool
8491

8592
public function read(int $length): string
8693
{
87-
if ($this->eof()) {
94+
if ($this->isClosed) {
8895
throw new \RuntimeException("Stream is closed");
8996
}
9097

test/Internal/PsrMessageStreamTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ public function testTell(): void
9393
self::assertSame('', $requestStream->read(8192));
9494
self::assertSame(6, $requestStream->tell());
9595
self::assertTrue($requestStream->eof());
96-
self::assertFalse($requestStream->isReadable());
97-
96+
self::assertTrue($requestStream->isReadable());
9897
}
9998

10099
public function testRewindThrowsException(): void

test/PsrAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function testToPsrResponseReturnsResponseWithStreamableBody(): void
267267

268268
self::assertSame('content', $body->read(8192));
269269
self::assertTrue($body->eof());
270-
self::assertFalse($body->isReadable());
270+
self::assertTrue($body->isReadable());
271271
}
272272

273273
public function testFromPsrResponseWithRequestReturnsResultWithSameRequest(): void

0 commit comments

Comments
 (0)