fix(core,admin_basic,board,ecommerce,page,gdpr,verification): 설정 미러·자동 정리·탈퇴 원자성·일괄 선택 범위 정비
공개이슈 ··· 및 그 전수 해소분. - 설정 저장·복원·초기화가 상주 프로세스 미러를 갱신하도록 단일 소유자화 - 만료 데이터 자동 정리 예약 12종 신설, 파기는 기본키 배치로 분할 - 회원 탈퇴를 전 경로 원자화하고 관리자 상태변경 경로를 정식 탈퇴로 통일 - 일괄 처리 목록의 선택을 화면에 보이는 행으로 한정(selectionScope) - 비밀번호 정책 문구를 도메인 중립 라벨로 정정 - 정적 검사 2종·검증 스킬 설계 정합성 축 신설
This commit is contained in:
1 parent
49c155509e
commit
4e1ec6e001
136 files changed
+7016
-504
No files matched your search
@@ -0,0 +1,330 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use App\Models\Schedule as ScheduleModel;
|
||||
use App\Providers\SettingsServiceProvider;
|
||||
use App\Repositories\JsonConfigRepository;
|
||||
use Illuminate\Console\Scheduling\Event;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 코어 만료 데이터 정리 스케줄 등록 회귀 테스트 (공개이슈 #110)
|
||||
*
|
||||
* 이 축의 테스트가 0건이었던 것이 "커맨드는 있는데 스케줄만 없다" 는 결함군이
|
||||
* 무가드로 통과된 구조적 원인입니다. 등록 전수와 실행 시각 기준을 함께 고정합니다.
|
||||
*
|
||||
* 서머타임 주의: 서머타임이 있는 시간대에서는 전환일에 특정 시각이 건너뛰거나
|
||||
* 두 번 발생할 수 있습니다. 아래 정리 배치는 모두 멱등이라 이중 실행이 데이터를
|
||||
* 해치지 않고, 건너뛴 날은 다음 날 배치가 흡수합니다.
|
||||
*
|
||||
* @scenario schedule_axis=code_registered, schedule_axis=admin_registered, timezone_setting=configured, timezone_setting=empty
|
||||
*
|
||||
* @effects all_gc_commands_are_registered_in_schedule, gc_commands_run_on_one_server_only, sanctum_prune_uses_hours_option, schedule_timezone_follows_site_general_timezone, schedule_timezone_falls_back_to_app_timezone_when_unset, app_timezone_stays_utc, admin_registered_schedule_next_run_uses_same_basis, new_commands_are_in_schedule_security_allowlist, new_commands_are_exposed_in_dev_dashboard
|
||||
*/
|
||||
class CoreScheduleRegistrationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @var string 부팅 시점에 확정된 예약 시각 기준 */
|
||||
private string $bootScheduleTimezone = 'UTC';
|
||||
|
||||
/**
|
||||
* B1: 코어 GC 스케줄 전수가 등록되어 있고 주기/onOneServer 가 의도대로다.
|
||||
*/
|
||||
public function test_core_gc_schedules_are_registered(): void
|
||||
{
|
||||
$expected = [
|
||||
'sanctum:prune-expired' => '0 4 * * *',
|
||||
'auth:clear-resets' => '5 4 * * *',
|
||||
'queue:prune-failed' => '10 4 * * *',
|
||||
'queue:prune-batches' => '15 4 * * *',
|
||||
'notification:cleanup' => '20 4 * * *',
|
||||
'ext-bundles:cleanup' => '25 4 * * *',
|
||||
'seo:prune-stats' => '30 4 * * *',
|
||||
'schedules:prune-history' => '35 4 * * *',
|
||||
'identity:prune-logs' => '40 4 * * *',
|
||||
'activity-log:prune' => '45 4 * * *',
|
||||
'notification-log:prune' => '50 4 * * *',
|
||||
'identity:expire-challenges' => '0 * * * *',
|
||||
];
|
||||
|
||||
foreach ($expected as $command => $expression) {
|
||||
$event = $this->findScheduledEvent($command);
|
||||
|
||||
$this->assertNotNull($event, "{$command} 스케줄이 등록되어야 합니다.");
|
||||
$this->assertSame($expression, $event->expression, "{$command} 실행 주기");
|
||||
$this->assertTrue($event->onOneServer, "{$command} 는 다중 서버에서 1대만 실행해야 합니다.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* B1: sanctum 정리는 --hours=24 로 실행된다.
|
||||
*/
|
||||
public function test_sanctum_prune_uses_expected_hours_option(): void
|
||||
{
|
||||
$event = $this->findScheduledEvent('sanctum:prune-expired');
|
||||
|
||||
$this->assertNotNull($event);
|
||||
$this->assertStringContainsString('--hours', (string) $event->command);
|
||||
$this->assertStringContainsString('24', (string) $event->command);
|
||||
}
|
||||
|
||||
/**
|
||||
* B1-t: 예약 시각 기준은 사이트 설정 시간대(general.timezone)를 따른다.
|
||||
*/
|
||||
public function test_schedule_timezone_follows_site_general_timezone(): void
|
||||
{
|
||||
// 테스트가 주입한 값을 그대로 되읽으면 파생 로직을 지워도 통과한다 —
|
||||
// 사이트 설정에서 app.schedule_timezone 이 실제로 파생되는지를 본다.
|
||||
Config::set('app', Arr::except(config('app'), ['schedule_timezone']));
|
||||
|
||||
$this->applyGeneralSettings(['timezone' => 'Europe/Berlin']);
|
||||
|
||||
$this->assertSame(
|
||||
'Europe/Berlin',
|
||||
config('app.schedule_timezone'),
|
||||
'사이트 설정 시간대가 예약 시각 기준으로 파생되지 않습니다'
|
||||
);
|
||||
|
||||
// 사용자 표시용 기본 타임존도 같은 값에서 파생된다 (기존 계약 유지)
|
||||
$this->assertSame('Europe/Berlin', config('app.default_user_timezone'));
|
||||
|
||||
// 저장 타임존은 UTC 불변 — 전 도메인의 저장값 해석 기준이라 건드리지 않는다.
|
||||
$this->assertSame('UTC', config('app.timezone'));
|
||||
}
|
||||
|
||||
/**
|
||||
* B1-t: 사이트 설정에 시간대가 없으면 파생 키 자체를 만들지 않는다.
|
||||
*/
|
||||
public function test_schedule_timezone_is_not_derived_when_setting_is_empty(): void
|
||||
{
|
||||
Config::set('app', Arr::except(config('app'), ['schedule_timezone']));
|
||||
|
||||
$this->applyGeneralSettings(['site_name' => '시간대 없는 사이트']);
|
||||
|
||||
$this->assertFalse(
|
||||
Config::has('app.schedule_timezone'),
|
||||
'시간대 미설정인데 파생 키가 생겨 Laravel 폴백이 차단됩니다'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* B1-o: 정리 예약 전건이 관리자 화면에서도 등록 가능해야 한다 (artisan 허용목록).
|
||||
*
|
||||
* 허용목록에 없으면 운영자가 주기를 바꾸거나 임시로 다시 걸 수 없고, 그 사실이
|
||||
* 등록 시점의 거부로만 드러난다.
|
||||
*/
|
||||
public function test_gc_commands_are_registerable_through_the_admin_allowlist(): void
|
||||
{
|
||||
$allowlist = (array) config('schedule_security.artisan.allowlist');
|
||||
$commands = $this->gcCommandNames();
|
||||
|
||||
$this->assertNotEmpty($commands, '정리 예약을 소스에서 도출하지 못했습니다.');
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$this->assertArrayHasKey(
|
||||
$command,
|
||||
$allowlist,
|
||||
"{$command} 가 artisan 허용목록에 없어 관리자가 예약으로 등록할 수 없습니다."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* B1-o: 이 저장소가 소유한 정리 커맨드는 개발 대시보드에서 수동 실행 가능해야 한다.
|
||||
*
|
||||
* 배치가 실패한 날 운영자가 손으로 돌릴 통로가 없으면 다음 배치까지 방치된다.
|
||||
* 프레임워크·벤더 커맨드(`sanctum:prune-expired` 등)는 대시보드 노출 대상이 아니므로
|
||||
* 소유 커맨드(`app/Console/Commands`)로 한정한다 — 노출 정합 검사와 같은 범위다.
|
||||
*/
|
||||
public function test_owned_gc_commands_are_exposed_in_the_dev_dashboard(): void
|
||||
{
|
||||
$dashboard = (string) file_get_contents(resource_path('views/dev-dashboard.blade.php'));
|
||||
$owned = $this->ownedCommandNames();
|
||||
|
||||
$checked = 0;
|
||||
|
||||
foreach ($this->gcCommandNames() as $command) {
|
||||
if (! in_array($command, $owned, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$checked++;
|
||||
$this->assertStringContainsString(
|
||||
"runCommand('{$command}')",
|
||||
$dashboard,
|
||||
"{$command} 실행 버튼이 개발 대시보드에 없습니다."
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertGreaterThan(0, $checked, '소유 정리 커맨드를 하나도 판정하지 못했습니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 이 저장소가 소유한(= `app/Console/Commands` 에 정의된) artisan 커맨드 이름 목록.
|
||||
*
|
||||
* @return array<int, string> 커맨드 이름 목록
|
||||
*/
|
||||
private function ownedCommandNames(): array
|
||||
{
|
||||
$root = base_path('app'.DIRECTORY_SEPARATOR.'Console'.DIRECTORY_SEPARATOR.'Commands');
|
||||
$names = [];
|
||||
|
||||
foreach (Artisan::all() as $name => $command) {
|
||||
$file = (new \ReflectionClass($command))->getFileName();
|
||||
|
||||
if ($file !== false && str_starts_with((string) $file, $root)) {
|
||||
$names[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* 정리 예약 커맨드 이름을 예약 정의 소스에서 도출합니다.
|
||||
*
|
||||
* 손으로 적은 목록은 예약이 늘어도 그대로라 전수를 증명하지 못합니다 —
|
||||
* 다중 서버 1대 실행(`onOneServer`)으로 선언된 artisan 예약을 그대로 읽습니다.
|
||||
*
|
||||
* @return array<int, string> 커맨드 이름 목록
|
||||
*/
|
||||
private function gcCommandNames(): array
|
||||
{
|
||||
$source = (string) file_get_contents(base_path('routes/console.php'));
|
||||
|
||||
$begin = strpos($source, '// gc-schedules:begin');
|
||||
$end = strpos($source, '// gc-schedules:end');
|
||||
|
||||
$this->assertNotFalse($begin, '정리 예약 구간 시작 표식이 없습니다.');
|
||||
$this->assertNotFalse($end, '정리 예약 구간 종료 표식이 없습니다.');
|
||||
|
||||
// 표식 밖의 예약(geoip 갱신·sitemap 생성 등)은 정리 배치가 아니다 —
|
||||
// `onOneServer()` 만으로 거르면 그런 예약까지 대상이 되어 오탐이 난다.
|
||||
$region = substr($source, $begin, $end - $begin);
|
||||
|
||||
preg_match_all("/Schedule::command\(\s*'([^']+)'/", $region, $matches);
|
||||
|
||||
return array_values(array_unique($matches[1] ?? []));
|
||||
}
|
||||
|
||||
/**
|
||||
* B1-t: 등록된 예약 이벤트 전부가 같은 시각 기준을 공유한다.
|
||||
*/
|
||||
public function test_every_scheduled_event_shares_the_same_timezone(): void
|
||||
{
|
||||
$events = app(Schedule::class)->events();
|
||||
|
||||
$this->assertNotEmpty($events);
|
||||
|
||||
// 기대값을 특정 시간대로 박으면 사이트 설정이 다른 환경·CI 에서 실패한다.
|
||||
// Schedule 인스턴스가 부팅 시점에 해석한 값과 대조한다.
|
||||
foreach ($events as $event) {
|
||||
$this->assertSame(
|
||||
$this->bootScheduleTimezone,
|
||||
(string) $event->timezone,
|
||||
'예약 이벤트가 서로 다른 시각 기준을 씁니다: '.$event->command
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 사이트 general 설정을 주고 Provider 의 파생 로직을 실행합니다.
|
||||
*
|
||||
* @param array<string, mixed> $general general 카테고리 설정값
|
||||
*/
|
||||
private function applyGeneralSettings(array $general): void
|
||||
{
|
||||
$repository = Mockery::mock(JsonConfigRepository::class);
|
||||
$repository->shouldReceive('getCategory')->with('general')->andReturn($general);
|
||||
$repository->shouldReceive('getCategory')->andReturn([]);
|
||||
|
||||
$provider = new SettingsServiceProvider($this->app);
|
||||
$apply = new \ReflectionMethod($provider, 'applyAppConfig');
|
||||
$apply->setAccessible(true);
|
||||
$apply->invoke($provider, $repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* B1-t: 사이트 설정 시간대가 비어 있으면 종전대로 app.timezone 으로 폴백한다.
|
||||
*/
|
||||
public function test_schedule_timezone_falls_back_to_app_timezone(): void
|
||||
{
|
||||
$kernel = app(ConsoleKernelContract::class);
|
||||
$resolve = new \ReflectionMethod($kernel, 'scheduleTimezone');
|
||||
$resolve->setAccessible(true);
|
||||
|
||||
// 사이트 설정에 시간대가 없으면 Provider 가 키 자체를 세팅하지 않는다(= 부재).
|
||||
Config::set('app', Arr::except(config('app'), ['schedule_timezone']));
|
||||
$this->assertFalse(Config::has('app.schedule_timezone'));
|
||||
$this->assertSame(config('app.timezone'), $resolve->invoke($kernel));
|
||||
|
||||
Config::set('app.schedule_timezone', 'Asia/Seoul');
|
||||
$this->assertSame('Asia/Seoul', $resolve->invoke($kernel));
|
||||
}
|
||||
|
||||
/**
|
||||
* B1-a: 관리자 등록 예약의 다음 실행 시각도 같은 기준으로 계산된다.
|
||||
*/
|
||||
public function test_admin_registered_schedule_next_run_uses_site_timezone(): void
|
||||
{
|
||||
$schedule = new ScheduleModel([
|
||||
'expression' => '0 4 * * *',
|
||||
'is_active' => true,
|
||||
]);
|
||||
$schedule->calculateNextRunAt();
|
||||
|
||||
$this->assertNotNull($schedule->next_run_at);
|
||||
|
||||
// 사이트 설정 시간대(Asia/Seoul, UTC+9)의 04:00 = UTC 19:00
|
||||
$this->assertSame(
|
||||
'04:00',
|
||||
$schedule->next_run_at->copy()->setTimezone('Asia/Seoul')->format('H:i')
|
||||
);
|
||||
$this->assertSame('19:00', $schedule->next_run_at->copy()->utc()->format('H:i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 테스트 시간대 고정 — 사이트 설정 시간대를 Asia/Seoul 로 두고 앱을 부팅한다.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// 예약 이벤트의 시각 기준은 부팅 시점에 확정된다 — 아래 주입은 그 뒤라
|
||||
// 이미 등록된 이벤트에는 영향이 없다. 대조용으로 부팅 값을 먼저 붙잡는다.
|
||||
$this->bootScheduleTimezone = (string) (
|
||||
config('app.schedule_timezone') ?? config('app.timezone', 'UTC')
|
||||
);
|
||||
|
||||
// 아래 계산 시점 해석(관리자 등록 예약)을 고정하기 위한 주입.
|
||||
Config::set('app.schedule_timezone', 'Asia/Seoul');
|
||||
}
|
||||
|
||||
/**
|
||||
* 부팅된 앱의 스케줄러에서 커맨드 이름으로 이벤트를 찾습니다.
|
||||
*
|
||||
* @param string $command artisan 커맨드 이름
|
||||
* @return Event|null 등록된 스케줄 이벤트
|
||||
*/
|
||||
private function findScheduledEvent(string $command): ?Event
|
||||
{
|
||||
foreach (app(Schedule::class)->events() as $event) {
|
||||
if (str_contains((string) $event->command, "'{$command}'")
|
||||
|| str_contains((string) $event->command, " {$command} ")
|
||||
|| str_ends_with((string) $event->command, " {$command}")) {
|
||||
return $event;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use App\Enums\IdentityVerificationStatus;
|
||||
use App\Extension\HookManager;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\IdentityVerificationLog;
|
||||
use App\Models\NotificationLog;
|
||||
use App\Models\Schedule as ScheduleModel;
|
||||
use App\Models\ScheduleHistory;
|
||||
use App\Models\SeoCacheStat;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 만료/누적 데이터 정리 커맨드 테스트 (공개이슈 #110 전수 해소분)
|
||||
*
|
||||
* 각 커맨드가 보존 기간을 넘긴 행만 지우고 기간 이내 행은 보존하는지 고정합니다.
|
||||
*
|
||||
* @scenario row_age=within_retention, row_age=beyond_retention
|
||||
*
|
||||
* @effects rows_beyond_retention_are_deleted, rows_within_retention_are_kept, identity_challenges_transition_without_deletion, automated_prune_emits_its_own_hooks
|
||||
*/
|
||||
class DataRetentionCommandsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* B2: seo:prune-stats — 보존 기간 초과 통계만 삭제.
|
||||
*/
|
||||
public function test_seo_prune_stats_removes_only_expired_rows(): void
|
||||
{
|
||||
$old = SeoCacheStat::create(['url' => '/old', 'locale' => 'ko', 'type' => 'hit']);
|
||||
$old->forceFill(['created_at' => now()->subDays(40)])->saveQuietly();
|
||||
|
||||
$recent = SeoCacheStat::create(['url' => '/recent', 'locale' => 'ko', 'type' => 'hit']);
|
||||
$recent->forceFill(['created_at' => now()->subDays(5)])->saveQuietly();
|
||||
|
||||
$this->artisan('seo:prune-stats', ['--days' => 30])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('seo_cache_stats', ['id' => $old->id]);
|
||||
$this->assertDatabaseHas('seo_cache_stats', ['id' => $recent->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* B3: schedules:prune-history — 보존 기간 초과 이력만 삭제.
|
||||
*/
|
||||
public function test_schedule_history_prune_removes_only_expired_rows(): void
|
||||
{
|
||||
$schedule = ScheduleModel::create([
|
||||
'name' => '테스트 스케줄',
|
||||
'type' => 'artisan',
|
||||
'command' => 'inspire',
|
||||
'expression' => '0 4 * * *',
|
||||
'frequency' => 'daily',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$old = ScheduleHistory::create([
|
||||
'schedule_id' => $schedule->id,
|
||||
'started_at' => now()->subDays(120),
|
||||
'status' => 'success',
|
||||
]);
|
||||
$recent = ScheduleHistory::create([
|
||||
'schedule_id' => $schedule->id,
|
||||
'started_at' => now()->subDays(10),
|
||||
'status' => 'success',
|
||||
]);
|
||||
|
||||
$this->artisan('schedules:prune-history', ['--days' => 90])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('schedule_histories', ['id' => $old->id]);
|
||||
$this->assertDatabaseHas('schedule_histories', ['id' => $recent->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* B4: identity:expire-challenges — 만료 challenge 만 상태 전환(비파괴).
|
||||
*/
|
||||
public function test_identity_expire_challenges_transitions_only_past_due(): void
|
||||
{
|
||||
$pastDue = $this->createIdentityLog(IdentityVerificationStatus::Requested->value, now()->subMinutes(10));
|
||||
$future = $this->createIdentityLog(IdentityVerificationStatus::Requested->value, now()->addMinutes(10));
|
||||
|
||||
$this->artisan('identity:expire-challenges')->assertSuccessful();
|
||||
|
||||
$this->assertSame(
|
||||
IdentityVerificationStatus::Expired->value,
|
||||
IdentityVerificationLog::find($pastDue->id)->status->value
|
||||
);
|
||||
$this->assertSame(
|
||||
IdentityVerificationStatus::Requested->value,
|
||||
IdentityVerificationLog::find($future->id)->status->value
|
||||
);
|
||||
|
||||
// 비파괴 — 행 자체는 남는다.
|
||||
$this->assertDatabaseHas('identity_verification_logs', ['id' => $pastDue->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* B6: identity:prune-logs — 보관 기간 초과 이력만 파기.
|
||||
*/
|
||||
public function test_identity_prune_logs_removes_only_expired_rows(): void
|
||||
{
|
||||
$old = $this->createIdentityLog(IdentityVerificationStatus::Verified->value, now()->subDays(200));
|
||||
$old->forceFill(['created_at' => now()->subDays(200)])->saveQuietly();
|
||||
|
||||
$recent = $this->createIdentityLog(IdentityVerificationStatus::Verified->value, now()->subDays(10));
|
||||
$recent->forceFill(['created_at' => now()->subDays(10)])->saveQuietly();
|
||||
|
||||
$this->artisan('identity:prune-logs', ['--days' => 180])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('identity_verification_logs', ['id' => $old->id]);
|
||||
$this->assertDatabaseHas('identity_verification_logs', ['id' => $recent->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* B7: activity-log:prune — 보존 기간 초과 로그만 삭제.
|
||||
*/
|
||||
public function test_activity_log_prune_removes_only_expired_rows(): void
|
||||
{
|
||||
$old = ActivityLog::create([
|
||||
'log_type' => 'system',
|
||||
'action' => 'test.old',
|
||||
'created_at' => now()->subDays(400),
|
||||
]);
|
||||
$recent = ActivityLog::create([
|
||||
'log_type' => 'system',
|
||||
'action' => 'test.recent',
|
||||
'created_at' => now()->subDays(10),
|
||||
]);
|
||||
|
||||
$this->artisan('activity-log:prune', ['--days' => 365])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('activity_logs', ['id' => $old->id]);
|
||||
$this->assertDatabaseHas('activity_logs', ['id' => $recent->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* B8: notification-log:prune — 보존 기간 초과 발송 이력만 삭제.
|
||||
*/
|
||||
public function test_notification_log_prune_removes_only_expired_rows(): void
|
||||
{
|
||||
$old = NotificationLog::create([
|
||||
'channel' => 'mail',
|
||||
'notification_type' => 'test',
|
||||
'recipient_identifier' => 'a@example.com',
|
||||
'status' => 'sent',
|
||||
]);
|
||||
$old->forceFill(['created_at' => now()->subDays(120)])->saveQuietly();
|
||||
|
||||
$recent = NotificationLog::create([
|
||||
'channel' => 'mail',
|
||||
'notification_type' => 'test',
|
||||
'recipient_identifier' => 'b@example.com',
|
||||
'status' => 'sent',
|
||||
]);
|
||||
$recent->forceFill(['created_at' => now()->subDays(10)])->saveQuietly();
|
||||
|
||||
$this->artisan('notification-log:prune', ['--days' => 90])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('notification_logs', ['id' => $old->id]);
|
||||
$this->assertDatabaseHas('notification_logs', ['id' => $recent->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 자동 파기는 운영자 일괄 삭제와 별개의 훅을 발행한다.
|
||||
*
|
||||
* 운영자 삭제 훅(`*.before_delete_many` 등)에는 본인인증 같은 대화형 가드가 물려
|
||||
* 있어 무인 예약이 탈 수 없다. 그렇다고 훅 없이 지우면 확장은 가장 큰 삭제 경로를
|
||||
* 볼 방법이 사라진다 — 전용 훅이 그 자리를 대신한다.
|
||||
*
|
||||
* @effects automated_prune_emits_its_own_hooks
|
||||
*/
|
||||
public function test_automated_prune_emits_its_own_hooks(): void
|
||||
{
|
||||
$fired = [];
|
||||
|
||||
foreach ([
|
||||
'core.activity_log.before_prune',
|
||||
'core.activity_log.after_prune',
|
||||
'core.notification_log.before_prune',
|
||||
'core.notification_log.after_prune',
|
||||
'core.schedule.before_prune_history',
|
||||
'core.schedule.after_prune_history',
|
||||
] as $hook) {
|
||||
HookManager::addAction($hook, function () use (&$fired, $hook) {
|
||||
$fired[] = $hook;
|
||||
});
|
||||
}
|
||||
|
||||
$this->artisan('activity-log:prune', ['--days' => 365])->assertSuccessful();
|
||||
$this->artisan('notification-log:prune', ['--days' => 90])->assertSuccessful();
|
||||
$this->artisan('schedules:prune-history', ['--days' => 90])->assertSuccessful();
|
||||
|
||||
$this->assertSame([
|
||||
'core.activity_log.before_prune',
|
||||
'core.activity_log.after_prune',
|
||||
'core.notification_log.before_prune',
|
||||
'core.notification_log.after_prune',
|
||||
'core.schedule.before_prune_history',
|
||||
'core.schedule.after_prune_history',
|
||||
], $fired, '자동 파기 커맨드가 도메인 계층을 건너뛰면 이 훅들이 발행되지 않습니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 보존 기간 하한은 도메인 계층이 소유한다 — `--days=0` 이어도 오늘 데이터는 남는다.
|
||||
*
|
||||
* 커맨드가 클램프를 들고 있으면 다른 호출자가 생길 때 그 보호가 따라오지 않는다.
|
||||
*
|
||||
* @effects retention_floor_is_owned_by_the_domain_layer
|
||||
*/
|
||||
public function test_retention_floor_is_enforced_below_the_command(): void
|
||||
{
|
||||
$today = ActivityLog::create([
|
||||
'log_type' => 'system',
|
||||
'action' => 'test.today',
|
||||
'description' => '오늘 기록',
|
||||
]);
|
||||
|
||||
$this->artisan('activity-log:prune', ['--days' => 0])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('activity_logs', ['id' => $today->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 본인인증 로그 생성 헬퍼
|
||||
*
|
||||
* @param string $status 상태값
|
||||
* @param Carbon $expiresAt 만료 시각
|
||||
* @return IdentityVerificationLog 생성된 로그
|
||||
*/
|
||||
private function createIdentityLog(string $status, $expiresAt): IdentityVerificationLog
|
||||
{
|
||||
return IdentityVerificationLog::create([
|
||||
'id' => (string) Str::uuid(),
|
||||
'provider_id' => 'test-provider',
|
||||
'purpose' => 'signup',
|
||||
'channel' => 'sms',
|
||||
'target_hash' => hash('sha256', Str::random()),
|
||||
'status' => $status,
|
||||
'expires_at' => $expiresAt,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user