Skip to content

Commit

Permalink
Merge pull request #115 from rn0/handle_empty_files
Browse files Browse the repository at this point in the history
SplFileInfoHandler should handle empty files
  • Loading branch information
szymach authored Sep 25, 2019
2 parents 8a45523 + d009911 commit eee1ee8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ private function tryTellFile($fileObject): int

private function tryReadFile(SplFileObject $fileObject, int $length): string
{
if ($length === 0) {
return '';
}

$content = $fileObject->fread($length);

if (false === $content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public function testGetContent()
$this->assertEquals(self::CONTENT, $content);
}

public function testGetContentOnEmptyFile()
{
$emptyFile = new SplTempFileObject();

$content = $this->handler->getContent($emptyFile);
$this->assertEquals('', $content);
}

public function testGetContentOnTempFile()
{
$input = new SplTempFileObject();
Expand Down

0 comments on commit eee1ee8

Please sign in to comment.