public function seek($offset, $whence = SEEK_SET) { parent::seek($offset, $whence); if (fseek($this->stream, $offset, $whence) === -1) { throw new \Exception(sprintf('Unable to seek to stream position %d with whence %s', $offset, var_export($whence, true))); } }
/** * @expectedException Innmind\Filesystem\Exception\PositionNotSeekableException */ public function testThrowWhenPositionNotSeekable() { $resource = fopen('php://temp', 'r+'); fwrite($resource, 'Lorem ipsum dolor'); $stream = new Stream($resource); $stream->seek(200); }
public function testOverwrite() { $s = new Stream(); $s->open(STREAM_MODE_READWRITE); $s->writeLine('Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur aliquam.'); $s->seek(20); $s->writeLine('Lorem ipsum dolor sit amet.'); $this->assertEquals($s->buffer, "Lorem ipsum dolor siLorem ipsum dolor sit amet.\ning elit. Curabitur aliquam.\n"); }