Setzt Phase 1 aus Visualization.md um: Vanilla-PHP-REST-API mit SQLite-Persistenz, statischen API-Keys pro Agent, Codeberg-Sync fuer Backlog/Done, PHPUnit-Tests und vollstaendiger API.md-Dokumentation - Vorgaben aus Detailantworten.md (F1-F16) umgesetzt. Entwicklung/Build/Test laufen komplett in Docker-Compose-Containern (PHP 8.2 + SQLite + Composer + PHPUnit/pcov), analog zum NC-Gantt-Projekt ist auf dem Host kein PHP/Composer noetig. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
135 lines
4.1 KiB
PHP
135 lines
4.1 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\TicketRepository;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class TicketRepositoryTest extends TestCase
|
|
{
|
|
private TicketRepository $repository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->repository = new TicketRepository(Database::inMemory());
|
|
}
|
|
|
|
public function testCreateDefaultsToBacklogColumn(): void
|
|
{
|
|
$ticket = $this->repository->create(['title' => 'Neues Ticket']);
|
|
|
|
self::assertSame('backlog', $ticket['column_name']);
|
|
self::assertSame('Neues Ticket', $ticket['title']);
|
|
}
|
|
|
|
public function testCreateRejectsUnknownColumn(): void
|
|
{
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
$this->repository->create(['title' => 'X', 'column' => 'unknown']);
|
|
}
|
|
|
|
public function testUpdateMovesTicketToAnotherColumn(): void
|
|
{
|
|
$ticket = $this->repository->create(['title' => 'X']);
|
|
|
|
$updated = $this->repository->update((int) $ticket['id'], ['column' => 'in_arbeit']);
|
|
|
|
self::assertSame('in_arbeit', $updated['column_name']);
|
|
}
|
|
|
|
public function testUpdateRejectsUnknownColumn(): void
|
|
{
|
|
$ticket = $this->repository->create(['title' => 'X']);
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
$this->repository->update((int) $ticket['id'], ['column' => 'unknown']);
|
|
}
|
|
|
|
public function testUpdateThrowsNotFoundForMissingTicket(): void
|
|
{
|
|
$this->expectException(NotFoundException::class);
|
|
|
|
$this->repository->update(999, ['column' => 'bereit']);
|
|
}
|
|
|
|
public function testAllFiltersByColumn(): void
|
|
{
|
|
$this->repository->create(['title' => 'A', 'column' => 'backlog']);
|
|
$this->repository->create(['title' => 'B', 'column' => 'done']);
|
|
|
|
$backlog = $this->repository->all('backlog');
|
|
|
|
self::assertCount(1, $backlog);
|
|
self::assertSame('A', $backlog[0]['title']);
|
|
}
|
|
|
|
public function testAllOrdersByColumnThenCreatedAt(): void
|
|
{
|
|
$this->repository->create(['title' => 'first', 'column' => 'backlog']);
|
|
$this->repository->create(['title' => 'second', 'column' => 'backlog']);
|
|
|
|
$tickets = $this->repository->all();
|
|
|
|
self::assertSame('first', $tickets[0]['title']);
|
|
self::assertSame('second', $tickets[1]['title']);
|
|
}
|
|
|
|
public function testUpsertFromCodebergCreatesNewTicket(): void
|
|
{
|
|
$ticket = $this->repository->upsertFromCodeberg([
|
|
'external_ref' => '42',
|
|
'title' => 'Issue 42',
|
|
'description' => 'Body',
|
|
'column' => 'backlog',
|
|
'type' => 'bug',
|
|
'color' => '#ff0000',
|
|
]);
|
|
|
|
self::assertSame('42', $ticket['external_ref']);
|
|
self::assertSame('codeberg', $ticket['source']);
|
|
}
|
|
|
|
public function testUpsertFromCodebergUpdatesExistingBacklogTicket(): void
|
|
{
|
|
$this->repository->upsertFromCodeberg([
|
|
'external_ref' => '42',
|
|
'title' => 'Issue 42',
|
|
'column' => 'backlog',
|
|
]);
|
|
|
|
$updated = $this->repository->upsertFromCodeberg([
|
|
'external_ref' => '42',
|
|
'title' => 'Issue 42 (closed)',
|
|
'column' => 'done',
|
|
]);
|
|
|
|
self::assertSame('done', $updated['column_name']);
|
|
self::assertSame('Issue 42 (closed)', $updated['title']);
|
|
}
|
|
|
|
public function testUpsertFromCodebergDoesNotResetManuallyMovedTicket(): void
|
|
{
|
|
$this->repository->upsertFromCodeberg([
|
|
'external_ref' => '42',
|
|
'title' => 'Issue 42',
|
|
'column' => 'backlog',
|
|
]);
|
|
$ticket = $this->repository->findByExternalRef('42');
|
|
$this->repository->update((int) $ticket['id'], ['column' => 'in_arbeit']);
|
|
|
|
$result = $this->repository->upsertFromCodeberg([
|
|
'external_ref' => '42',
|
|
'title' => 'Issue 42 geaendert',
|
|
'column' => 'backlog',
|
|
]);
|
|
|
|
self::assertSame('in_arbeit', $result['column_name']);
|
|
}
|
|
}
|