file = $dir.'/laravel.log'; $this->app->instance(ErrorLog::class, new ErrorLog($dir)); file_put_contents($this->file, implode("\n", [ '[2026-09-27 10:00:00] production.INFO: audit: menu {"user_id":1}', '[2026-09-27 10:05:12] production.ERROR: Undefined array key "children" {"url":"POST https://portal.test/livewire/update","user_id":7,"exception":"[object] (ErrorException(code: 0): Undefined array key \"children\" at '.base_path('app/Filament/Pages/MenuSettings.php').':210)\n[stacktrace]\n#0 {main}\n"}', '#0 /var/www/vendor/foo.php(12): bar()', '[2026-09-27 10:06:00] production.WARNING: nur eine Warnung', ])."\n"); } protected function tearDown(): void { @unlink($this->file); parent::tearDown(); } public function test_recent_errors_are_parsed_with_place_and_url(): void { $errors = app(ErrorLog::class)->recent(); $this->assertCount(1, $errors); $this->assertSame('ErrorException', $errors[0]['exception']); $this->assertSame('app/Filament/Pages/MenuSettings.php:210', $errors[0]['where']); $this->assertSame('POST https://portal.test/livewire/update', $errors[0]['url']); $this->assertSame(7, $errors[0]['user']); } public function test_system_health_shows_them_to_administrators(): void { $this->actingAs(User::factory()->admin()->create()); Livewire::test(SystemHealth::class)->assertSee('Letzte Fehler')->assertSee('MenuSettings.php:210')->assertActionVisible('log'); $this->actingAs(User::factory()->create())->get('/admin/systemzustand')->assertForbidden(); } }