Bislang hat RepoConfigController::delete() nur die Projektkonfiguration geloescht - die Tickets des Projekts blieben (nur ohne Projektfarbe, Issue #34) dauerhaft im Kanban sichtbar. Jetzt loescht der Endpunkt zusaetzlich alle Tickets, deren repo-Feld auf das entfernte Projekt zeigt.
101 lines
3.3 KiB
PHP
101 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Monitor\Api\Tests\Repository;
|
|
|
|
use InvalidArgumentException;
|
|
use Monitor\Api\Db\Database;
|
|
use Monitor\Api\Http\NotFoundException;
|
|
use Monitor\Api\Repository\RepoConfigRepository;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class RepoConfigRepositoryTest extends TestCase
|
|
{
|
|
private RepoConfigRepository $repository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$db = Database::inMemory();
|
|
$db->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 testDeleteRemovesEntryAndReturnsIt(): void
|
|
{
|
|
$repo = $this->repository->create(['owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#fbca04']);
|
|
|
|
$deleted = $this->repository->delete((int) $repo['id']);
|
|
|
|
self::assertSame([], $this->repository->all());
|
|
self::assertSame('fds2610', $deleted['owner']);
|
|
self::assertSame('monitor', $deleted['repo']);
|
|
}
|
|
|
|
public function testDeleteUnknownIdThrowsNotFound(): void
|
|
{
|
|
$this->expectException(NotFoundException::class);
|
|
|
|
$this->repository->delete(999);
|
|
}
|
|
}
|