Skip to content

Commit

Permalink
Issue bovigo#222: Fix tests which incorrectly modelled EOF & offset
Browse files Browse the repository at this point in the history
Testing with normal files show that fread() does not progress the
pointer beyond the end of the file, and a read *beyond* the file size is
required before feof() returns true.
  • Loading branch information
IMSoP committed Feb 26, 2020
1 parent e4a5972 commit 28c71a7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
24 changes: 22 additions & 2 deletions tests/phpunit/content/StringBasedFileContentTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,38 @@ public function readLessThenSizeDoesNotReachEof(): void
/**
* @test
*/
public function readSizeReachesEof(): void
public function readSizeReachesDoesNotReachEof(): void
{
$this->stringBasedFileContent->read(9);
assertFalse($this->stringBasedFileContent->eof());
}

/**
* @test
*/
public function readSizeReachesEofOnNextRead(): void
{
$this->stringBasedFileContent->read(9);
$this->stringBasedFileContent->read(1);
assertTrue($this->stringBasedFileContent->eof());
}

/**
* @test
*/
public function readMoreThanSizeReachesEof(): void
public function readMoreThanSizeDoesNotReachEof(): void
{
$this->stringBasedFileContent->read(10);
assertFalse($this->stringBasedFileContent->eof());
}

/**
* @test
*/
public function readMoreThanSizeReachesEofOnNextRead(): void
{
$this->stringBasedFileContent->read(10);
$this->stringBasedFileContent->read(1);
assertTrue($this->stringBasedFileContent->eof());
}

Expand Down
21 changes: 8 additions & 13 deletions tests/phpunit/vfsStreamFileTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ public function contentCanBeChanged(): void
/**
* @test
*/
public function isAtEofWhenEmpty(): void
public function isNotAtEofWhenEmpty(): void
{
assertTrue($this->file->eof());
assertFalse($this->file->eof());
}

/**
Expand All @@ -169,19 +169,10 @@ public function readFromEmptyFileReturnsEmptyString(): void
/**
* @test
*/
public function readFromEmptyFileMovesPointer(): void
public function readFromEmptyFileDoesNotMovePointer(): void
{
$this->file->read(5);
assertThat($this->file->getBytesRead(), equals(5));
}

/**
* @test
*/
public function reportsAmountOfBytesReadEvenWhenEmpty(): void
{
$this->file->read(5);
assertThat($this->file->getBytesRead(), equals(5));
assertThat($this->file->getBytesRead(), equals(0));
}

/**
Expand Down Expand Up @@ -228,6 +219,10 @@ public function partialReads(): void

assertThat($this->file->read(3), equals('baz'));
assertThat($this->file->getBytesRead(), equals(9));
assertFalse($this->file->eof());

assertThat($this->file->read(1), equals(''));
assertThat($this->file->getBytesRead(), equals(9));
assertTrue($this->file->eof());
}

Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/vfsStreamWrapperFileTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public function recognizesEof(): void
{
$fp = fopen($this->fileInSubdir->url(), 'r');
fseek($fp, 1, SEEK_END);
fread($fp, 1);
assertTrue(feof($fp));
fclose($fp);
}
Expand Down

0 comments on commit 28c71a7

Please sign in to comment.