View source
<?php
namespace org\bovigo\vfs\content;
class LargeFileContentTestCase extends \PHPUnit_Framework_TestCase {
private $largeFileContent;
public function setUp() {
$this->largeFileContent = new LargeFileContent(100);
}
public function hasSizeOriginallyGiven() {
$this
->assertEquals(100, $this->largeFileContent
->size());
}
public function contentIsFilledUpWithSpacesIfNoDataWritten() {
$this
->assertEquals(str_repeat(' ', 100), $this->largeFileContent
->content());
}
public function readReturnsSpacesWhenNothingWrittenAtOffset() {
$this
->assertEquals(str_repeat(' ', 10), $this->largeFileContent
->read(10));
}
public function readReturnsContentFilledWithSpaces() {
$this->largeFileContent
->write('foobarbaz');
$this->largeFileContent
->seek(0, SEEK_SET);
$this
->assertEquals('foobarbaz ', $this->largeFileContent
->read(10));
}
public function writesDataAtStartWhenOffsetNotMoved() {
$this
->assertEquals(9, $this->largeFileContent
->write('foobarbaz'));
$this
->assertEquals('foobarbaz' . str_repeat(' ', 91), $this->largeFileContent
->content());
}
public function writeDataAtStartDoesNotIncreaseSize() {
$this
->assertEquals(9, $this->largeFileContent
->write('foobarbaz'));
$this
->assertEquals(100, $this->largeFileContent
->size());
}
public function writesDataAtOffsetWhenOffsetMoved() {
$this->largeFileContent
->seek(50, SEEK_SET);
$this
->assertEquals(9, $this->largeFileContent
->write('foobarbaz'));
$this
->assertEquals(str_repeat(' ', 50) . 'foobarbaz' . str_repeat(' ', 41), $this->largeFileContent
->content());
}
public function writeDataInBetweenDoesNotIncreaseSize() {
$this->largeFileContent
->seek(50, SEEK_SET);
$this
->assertEquals(9, $this->largeFileContent
->write('foobarbaz'));
$this
->assertEquals(100, $this->largeFileContent
->size());
}
public function writesDataOverEndWhenOffsetAndDataLengthLargerThanSize() {
$this->largeFileContent
->seek(95, SEEK_SET);
$this
->assertEquals(9, $this->largeFileContent
->write('foobarbaz'));
$this
->assertEquals(str_repeat(' ', 95) . 'foobarbaz', $this->largeFileContent
->content());
}
public function writeDataOverLastOffsetIncreasesSize() {
$this->largeFileContent
->seek(95, SEEK_SET);
$this
->assertEquals(9, $this->largeFileContent
->write('foobarbaz'));
$this
->assertEquals(104, $this->largeFileContent
->size());
}
public function writesDataAfterEndWhenOffsetAfterEnd() {
$this->largeFileContent
->seek(0, SEEK_END);
$this
->assertEquals(9, $this->largeFileContent
->write('foobarbaz'));
$this
->assertEquals(str_repeat(' ', 100) . 'foobarbaz', $this->largeFileContent
->content());
}
public function writeDataAfterLastOffsetIncreasesSize() {
$this->largeFileContent
->seek(0, SEEK_END);
$this
->assertEquals(9, $this->largeFileContent
->write('foobarbaz'));
$this
->assertEquals(109, $this->largeFileContent
->size());
}
public function truncateReducesSize() {
$this
->assertTrue($this->largeFileContent
->truncate(50));
$this
->assertEquals(50, $this->largeFileContent
->size());
}
public function truncateRemovesWrittenContentAfterOffset() {
$this->largeFileContent
->seek(45, SEEK_SET);
$this->largeFileContent
->write('foobarbaz');
$this
->assertTrue($this->largeFileContent
->truncate(50));
$this
->assertEquals(str_repeat(' ', 45) . 'fooba', $this->largeFileContent
->content());
}
public function createInstanceWithKilobytes() {
$this
->assertEquals(100 * 1024, LargeFileContent::withKilobytes(100)
->size());
}
public function createInstanceWithMegabytes() {
$this
->assertEquals(100 * 1024 * 1024, LargeFileContent::withMegabytes(100)
->size());
}
public function createInstanceWithGigabytes() {
$this
->assertEquals(100 * 1024 * 1024 * 1024, LargeFileContent::withGigabytes(100)
->size());
}
}