repo = $this->createMock(VisitDeleterRepositoryInterface::class); $this->visitsDeleter = new VisitsDeleter($this->repo); } #[Test, DataProvider('provideVisitsCounts')] public function returnsDeletedVisitsFromRepo(int $visitsCount): void { $this->repo->expects($this->once())->method('deleteOrphanVisits')->willReturn($visitsCount); $result = $this->visitsDeleter->deleteOrphanVisits(); self::assertEquals($visitsCount, $result->affectedItems); } public static function provideVisitsCounts(): iterable { yield '45' => [45]; yield '5000' => [5000]; yield '0' => [0]; } #[Test] public function returnsNoDeletedVisitsForApiKeyWithNoPermission(): void { $this->repo->expects($this->never())->method('deleteOrphanVisits'); $result = $this->visitsDeleter->deleteOrphanVisits( ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forNoOrphanVisits())), ); self::assertEquals(0, $result->affectedItems); } }