|
5 | 5 | use Opcodes\LogViewer\Logs\LogType; |
6 | 6 |
|
7 | 7 | it('can process new Horizon logs', function () { |
8 | | - $file = generateLogFile('horizon_new_dummy.log', content: <<<EOF |
| 8 | + $file = generateLogFile('horizon_new.log', content: <<<EOF |
9 | 9 | Horizon started successfully. |
10 | 10 | 2023-07-22 16:13:33 App\Jobs\TestJob ............................... RUNNING |
11 | 11 | 2023-07-22 16:13:34 App\Jobs\TestJob ............................... 1s DONE |
|
29 | 29 | ->and($logs[1]->message)->toBe('App\Jobs\TestJob') |
30 | 30 | ->and($logs[1]->context['duration'])->toBe('1s'); |
31 | 31 | }); |
| 32 | + |
| 33 | +it('processes weird cases', function () { |
| 34 | + $file = generateLogFile('horizon_new_weird.log', content: <<<EOF |
| 35 | +Horizon started successfully. |
| 36 | + 2023-08-17 07:22:32 App\Jobs\TestJob 1 s DONE |
| 37 | + 2023-08-18 06:05:03 App\Jobs\TestJob 32 s. DONE |
| 38 | + 2023-08-19 04:31:07 App\Jobs\TestJob .... 12 sek DONE |
| 39 | + 2023-08-20 02:15:58 App\Jobs\TestJob 2023-08-20 02:15:59 App\Jobs\TestJob 25.14ms DONE |
| 40 | +EOF); |
| 41 | + $file = new LogFile($file->path); |
| 42 | + |
| 43 | + expect($file->type()->value)->toBe(LogType::HORIZON); // HorizonLog |
| 44 | + |
| 45 | + $logReader = $file->logs()->scan(); |
| 46 | + |
| 47 | + expect($logs = $logReader->get())->toHaveCount(4) |
| 48 | + ->and($logs[0]->datetime->toDateTimeString())->toBe('2023-08-17 07:22:32') |
| 49 | + ->and($logs[0]->level)->toBe('DONE') |
| 50 | + ->and($logs[0]->getLevel())->toBeInstanceOf(HorizonStatusLevel::class) |
| 51 | + ->and($logs[0]->getLevel()->getName())->toBe('Done') |
| 52 | + ->and($logs[0]->message)->toBe('App\Jobs\TestJob') |
| 53 | + ->and($logs[0]->context['duration'])->toBe('1 s') |
| 54 | + |
| 55 | + ->and($logs[1]->datetime->toDateTimeString())->toBe('2023-08-18 06:05:03') |
| 56 | + ->and($logs[1]->level)->toBe('DONE') |
| 57 | + ->and($logs[1]->message)->toBe('App\Jobs\TestJob') |
| 58 | + ->and($logs[1]->context['duration'])->toBe('32 s.') |
| 59 | + |
| 60 | + ->and($logs[2]->datetime->toDateTimeString())->toBe('2023-08-19 04:31:07') |
| 61 | + ->and($logs[2]->level)->toBe('DONE') |
| 62 | + ->and($logs[2]->message)->toBe('App\Jobs\TestJob') |
| 63 | + ->and($logs[2]->context['duration'])->toBe('12 sek') |
| 64 | + |
| 65 | + // this one is weird, but let's drop the incomplete beginning and assume the rest of the line is |
| 66 | + // the correct log entry. |
| 67 | + ->and($logs[3]->datetime->toDateTimeString())->toBe('2023-08-20 02:15:59') |
| 68 | + ->and($logs[3]->level)->toBe('DONE') |
| 69 | + ->and($logs[3]->message)->toBe('App\Jobs\TestJob') |
| 70 | + ->and($logs[3]->context['duration'])->toBe('25.14ms'); |
| 71 | +}); |
0 commit comments