keep($snaps); $this->assertArrayHasKey('d119-b', $keep, 'newest is always kept'); $this->assertArrayHasKey('d119', $keep, 'last=2'); $this->assertContains('daily', $keep['d113-b']); $this->assertArrayNotHasKey('d113', $keep, 'only the newest of a day'); $this->assertLessThanOrEqual(2 + 7 + 4 + 3, count($keep)); $months = array_unique(array_map(fn ($id) => date('Y-m', $snaps[$id]), array_keys(array_filter($keep, fn ($r) => in_array('monthly', $r, true))))); $this->assertCount(3, $months); } public function testAPinnedSnapshotStaysAndDoesNotCount(): void { $policy = new RetentionPolicy(1, 0, 0, 0); $snaps = ['old' => 100, 'pinned' => 300, 'new' => 200]; $this->assertSame(['pinned'], array_keys($policy->keep($snaps)), 'without the pin it would take the place of "last"'); $keep = $policy->keepWithPinned($snaps, ['pinned', 'gone-already']); $this->assertSame(['pinned'], $keep['pinned']); $this->assertSame(['last'], $keep['new'], 'the newest one that is not pinned'); $this->assertArrayNotHasKey('old', $keep); $this->assertArrayNotHasKey('gone-already', $keep); } public function testKeepsEverythingWhenFewSnapshots(): void { $keep = (new RetentionPolicy())->keep(['a' => 100, 'b' => 200]); $this->assertSame(['a', 'b'], array_values(array_intersect(['a', 'b'], array_keys($keep)))); } }