<?php
declare(strict_types=1);

namespace Tests\FreshCloud\Mail\BaseStreamWrappers;

use FreshCloud\Mail\BaseStreamWrappers\StringStream;
use PHPUnit\Framework\TestCase;

final class StringStreamTest extends TestCase
{
    private StringStream $stream;

    protected function setUp(): void
    {
        $this->stream = new StringStream('initial data');
    }

    public function testRead(): void
    {
        $this->assertSame('initial', $this->stream->read(7));
        $this->assertSame(' data', $this->stream->read(5));
    }

    public function testWrite(): void
    {
        $this->stream->write('append');
        $this->assertSame('initial dataappend', $this->stream->read(20));
    }

    public function testTell(): void
    {
        $this->stream->read(5);
        $this->assertSame(5, $this->stream->tell());
    }

    public function testSeek(): void
    {
        $this->stream->seek(7);  // "initial data" -> skip "initial" (7 chars)
        $this->assertSame(' data', $this->stream->read(5));
    }

    public function testEof(): void
    {
        $this->stream->read(12);
        $this->assertTrue($this->stream->eof());
    }
}