Merge pull request #10771 from fabrixxm/issue/10766

Handle reading empty file in ReversedFileReader
This commit is contained in:
Hypolite Petovan 2021-09-27 07:13:14 -04:00 committed by GitHub
commit e53dcc3be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -95,6 +95,9 @@ class ReversedFileReader implements \Iterator
if ($this->pos == 0) {
return array_pop($buffer);
}
if (is_null($buffer)) {
return null;
}
if (count($buffer) > 1) {
return array_pop($buffer);
}

View File

@ -145,4 +145,16 @@ class ParsedLogIteratorTest extends TestCase
$pls = iterator_to_array($this->pli, false);
self::assertCount(0, $pls);
}
public function testEmptyLogFile()
{
$logfile = dirname(__DIR__) . '/../../datasets/log/empty.friendica.log.txt';
$reader = new ReversedFileReader();
$pli = new ParsedLogIterator($reader);
$pli->open($logfile);
$pls = iterator_to_array($pli, false);
self::assertCount(0, $pls);
}
}