-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix a bug with new logs sometimes overriding index of older logs
- Loading branch information
Showing
5 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Opcodes\LogViewer\LogFile; | ||
|
||
beforeEach(function () { | ||
$this->file = generateLogFile(); | ||
File::append($this->file->path, makeLogEntry()); | ||
}); | ||
|
||
afterEach(fn () => clearGeneratedLogFiles()); | ||
|
||
it('can scan a log file', function () { | ||
$logReader = $this->file->logs(); | ||
expect($logReader->requiresScan())->toBeTrue(); | ||
|
||
$logReader->scan(); | ||
|
||
expect($logReader->requiresScan())->toBeFalse() | ||
->and($logReader->index()->total())->toBe(1); | ||
}); | ||
|
||
it('can re-scan the file after a new entry has been added', function () { | ||
$logReader = $this->file->logs(); | ||
$logReader->scan(); | ||
|
||
\Spatie\TestTime\TestTime::addMinute(); | ||
|
||
File::append($this->file->path, PHP_EOL.makeLogEntry()); | ||
|
||
// re-instantiate the log reader to make sure we don't have anything cached | ||
$this->file = new LogFile($this->file->name, $this->file->path); | ||
$logReader = $this->file->logs(); | ||
expect($logReader->requiresScan())->toBeTrue(); | ||
|
||
$logReader->scan(); | ||
|
||
expect($logReader->requiresScan())->toBeFalse() | ||
->and($logReader->index()->total())->toBe(2) | ||
->and($logReader->index()->getFlatIndex())->toHaveCount(2); | ||
}); |
File renamed without changes.