~ancarda/psr7-string-stream

f0b0f839f9badef340fc5fa8bdbcb4f189114864 — Johan Meiring 5 months ago 685005f
Adjust EOF check to account for possible over-reading
2 files changed, 10 insertions(+), 1 deletions(-)

M src/StringStream.php
M tests/StringStreamTest.php
M src/StringStream.php => src/StringStream.php +1 -1
@@ 109,7 109,7 @@ class StringStream implements StreamInterface
     */
    public function eof(): bool
    {
        return $this->pointer === $this->length;
        return $this->pointer >= $this->length;
    }

    /**

M tests/StringStreamTest.php => tests/StringStreamTest.php +9 -0
@@ 207,4 207,13 @@ class StringStreamTest extends TestCase
        $this->expectExceptionMessage("You cannot call `getContents' on this stream because it's closed.");
        $stringStream->getContents();
    }

    public function testEOFAfterOverReading(): void
    {
        $stringStream = new StringStream('hello world');
        self::assertFalse($stringStream->eof());
        $text = $stringStream->read(1048576);
        self::assertSame('hello world', $text);
        self::assertTrue($stringStream->eof());
    }
}