pdo()->exec('DELETE FROM repo_configs'); $this->repository = new RepoConfigRepository($db); } public function testAllIsEmptyWithoutConfiguredProjects(): void { self::assertSame([], $this->repository->all()); } public function testCreateNormalizesColorAndAppendsAtEndOfSortOrder(): void { $first = $this->repository->create(['owner' => 'fds2610', 'repo' => 'monitor', 'color' => 'fbca04']); $second = $this->repository->create(['owner' => 'fds2610', 'repo' => 'Steuerkram', 'color' => '#28A745']); self::assertSame('#fbca04', $first['color']); self::assertSame('#28A745', $second['color']); self::assertSame([$first['id'], $second['id']], array_map( static fn (array $r): int => (int) $r['id'], $this->repository->all() )); } public function testCreateRejectsMissingOwnerOrRepo(): void { $this->expectException(InvalidArgumentException::class); $this->repository->create(['owner' => '', 'repo' => 'monitor', 'color' => '#fbca04']); } public function testCreateRejectsInvalidColor(): void { $this->expectException(InvalidArgumentException::class); $this->repository->create(['owner' => 'fds2610', 'repo' => 'monitor', 'color' => 'nicht-hex']); } public function testCreateRejectsDuplicateOwnerRepo(): void { $this->repository->create(['owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#fbca04']); $this->expectException(InvalidArgumentException::class); $this->repository->create(['owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#000000']); } public function testUpdateChangesFields(): void { $repo = $this->repository->create(['owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#fbca04']); $updated = $this->repository->update((int) $repo['id'], [ 'owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#000000', ]); self::assertSame('#000000', $updated['color']); } public function testUpdateUnknownIdThrowsNotFound(): void { $this->expectException(NotFoundException::class); $this->repository->update(999, ['owner' => 'a', 'repo' => 'b', 'color' => '#000000']); } public function testDeleteRemovesEntry(): void { $repo = $this->repository->create(['owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#fbca04']); $this->repository->delete((int) $repo['id']); self::assertSame([], $this->repository->all()); } public function testDeleteUnknownIdThrowsNotFound(): void { $this->expectException(NotFoundException::class); $this->repository->delete(999); } }