Skip to content
Open
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
15 changes: 12 additions & 3 deletions src/Internal/PsrMessageStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ final class PsrMessageStream implements StreamInterface

private bool $isEof = false;

private bool $isClosed = false;

private int $position = 0;

public function __construct(private readonly ReadableStream $source, private readonly ?int $size = null)
Expand All @@ -32,11 +34,14 @@ public function close(): void
$this->source->close();
$this->buffer = '';
$this->isEof = true;
$this->isClosed = true;
}

public function detach(): void
public function detach()
{
$this->close();

return null;
}

public function eof(): bool
Expand All @@ -46,6 +51,10 @@ public function eof(): bool

public function getContents(): string
{
if ($this->isClosed) {
throw new \RuntimeException("Stream is closed");
}

$buffer = $this->buffer;
$this->buffer = '';

Expand All @@ -69,7 +78,7 @@ public function getSize(): ?int

public function isReadable(): bool
{
return !$this->eof();
return !$this->isClosed;
}

public function isSeekable(): bool
Expand All @@ -84,7 +93,7 @@ public function isWritable(): bool

public function read(int $length): string
{
if ($this->eof()) {
if ($this->isClosed) {
throw new \RuntimeException("Stream is closed");
}

Expand Down
3 changes: 1 addition & 2 deletions test/Internal/PsrMessageStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public function testTell(): void
self::assertSame('', $requestStream->read(8192));
self::assertSame(6, $requestStream->tell());
self::assertTrue($requestStream->eof());
self::assertFalse($requestStream->isReadable());

self::assertTrue($requestStream->isReadable());
}

public function testRewindThrowsException(): void
Expand Down
2 changes: 1 addition & 1 deletion test/PsrAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function testToPsrResponseReturnsResponseWithStreamableBody(): void

self::assertSame('content', $body->read(8192));
self::assertTrue($body->eof());
self::assertFalse($body->isReadable());
self::assertTrue($body->isReadable());
}

public function testFromPsrResponseWithRequestReturnsResultWithSameRequest(): void
Expand Down
Loading