assertSame([$now - 5], array_values($kept), 'reindexed list of survivors'); } public function testKeepsRecentAndDropsExpiredInAssociativeMode(): void { $now = time(); $attempts = ['alice' => $now - 5, 'bob' => $now - 7200]; $kept = BruteforceGuard::truncateAttempts($attempts, 3600, false); $this->assertSame(['alice' => $now - 5], $kept, 'keys preserved for survivors'); $this->assertArrayNotHasKey('bob', $kept); } public function testEverythingWithinWindowIsKept(): void { $now = time(); $attempts = [$now, $now - 1, $now - 10]; $this->assertCount(3, BruteforceGuard::truncateAttempts($attempts, 3600, true)); } public function testEmptyInputYieldsEmpty(): void { $this->assertSame([], BruteforceGuard::truncateAttempts([], 60, true)); $this->assertSame([], BruteforceGuard::truncateAttempts([], 60, false)); } }