Skip to content

Commit 233d81f

Browse files
authored
Setup paginator when offset is greater than 0. (#19)
1 parent 911e056 commit 233d81f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Service/File/LogParser.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ public function parse(SplFileInfo $file, LogLineParserInterface $lineParser, Log
4141
$index->addLine($logLine);
4242
}
4343

44-
// stream reader didn't reach the end
45-
if ($lineIterator->isEOF() === false) {
46-
$index->setPaginator(new Paginator($logQuery->direction, $logQuery->offset === null, true, $lineIterator->getPosition()));
44+
// create paginator
45+
$hasOffset = (int)$logQuery->offset > 0;
46+
if ($lineIterator->isEOF() === false || $hasOffset) {
47+
$index->setPaginator(new Paginator($logQuery->direction, $hasOffset, $lineIterator->isEOF() === false, $lineIterator->getPosition()));
4748
}
4849

4950
return $index;

tests/Integration/Service/File/LogParserTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,19 @@ public function testParseAlmostEof(): void
9595
static::assertNotNull($index->getPaginator());
9696
}
9797

98+
public function testParsePaginatorWithOffset(): void
99+
{
100+
$query = new LogQueryDto('identifier', 5, '', DirectionEnum::Asc, null, null, 500);
101+
$file = new SplFileInfo($this->getResourcePath('Integration/Service/LogParser/monolog.log'), '', '');
102+
$index = $this->parser->parse($file, $this->lineParser, $query);
103+
104+
static::assertCount(99, $index->getLines());
105+
static::assertNotNull($index->getPaginator());
106+
}
107+
98108
public function testParseEof(): void
99109
{
100-
$query = new LogQueryDto('identifier', 0, '', DirectionEnum::Asc, null, null, 500);
110+
$query = new LogQueryDto('identifier', null, '', DirectionEnum::Asc, null, null, 500);
101111
$file = new SplFileInfo($this->getResourcePath('Integration/Service/LogParser/monolog.log'), '', '');
102112
$index = $this->parser->parse($file, $this->lineParser, $query);
103113

0 commit comments

Comments
 (0)