delete(); DB::table('site_visitors')->delete(); }); test('гости старше 180 дней удаляются, свежие остаются', function () { $old = (string) Str::uuid(); $fresh = (string) Str::uuid(); DB::table('site_visitors')->insert([ ['id' => $old, 'first_seen_at' => now()->subDays(200), 'last_seen_at' => now()->subDays(200)], ['id' => $fresh, 'first_seen_at' => now()->subDays(10), 'last_seen_at' => now()->subDays(10)], ]); $this->artisan('visitors:prune')->assertExitCode(0); expect(DB::table('site_visitors')->where('id', $old)->exists())->toBeFalse(); expect(DB::table('site_visitors')->where('id', $fresh)->exists())->toBeTrue(); }); test('срок хранения настраивается ключом --days', function () { $id = (string) Str::uuid(); DB::table('site_visitors')->insert([ ['id' => $id, 'first_seen_at' => now()->subDays(40), 'last_seen_at' => now()->subDays(40)], ]); $this->artisan('visitors:prune', ['--days' => 30])->assertExitCode(0); expect(DB::table('site_visitors')->where('id', $id)->exists())->toBeFalse(); });