systemUser(); $user = $this->operationalUser(['name' => 'Mario Rossi']); $this->purge()->execute($user); $user->refresh(); $this->assertSame('Deleted user', $user->name); $this->assertSame("deleted-{$user->id}@anonymized.invalid", $user->email); $this->assertNotNull($user->anonymized_at); $this->assertNull($user->email_verified_at); $this->assertNull($user->two_factor_setup_completed_at); $this->assertFalse($user->must_change_password); } public function test_it_is_idempotent_on_already_anonymized_users(): void { $this->systemUser(); $user = $this->operationalUser(['name' => 'Keep Me', 'anonymized_at' => now()]); $this->purge()->execute($user); $user->refresh(); // Già anonimizzato → uscita anticipata: nessuna riscrittura del nome. $this->assertSame('Keep Me', $user->name); } public function test_it_refuses_to_anonymize_the_system_user(): void { $system = $this->systemUser(); $this->expectException(CannotDeleteSystemUserException::class); $this->purge()->execute($system); } }