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>
58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Monitor\Api\Tests\Controller;
|
|
|
|
use Monitor\Api\Controller\KpiController;
|
|
use Monitor\Api\Db\Database;
|
|
use Monitor\Api\Http\Request;
|
|
use Monitor\Api\Repository\KpiRepository;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class KpiControllerTest extends TestCase
|
|
{
|
|
private KpiController $controller;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->controller = new KpiController(new KpiRepository(Database::inMemory()));
|
|
}
|
|
|
|
public function testReportRejectsMissingValue(): void
|
|
{
|
|
$response = $this->controller->report(Request::create('POST', '/api/v1/kpis/open_tickets', body: []), ['key' => 'open_tickets']);
|
|
|
|
self::assertSame(422, $response->status);
|
|
}
|
|
|
|
public function testReportRejectsNonNumericValue(): void
|
|
{
|
|
$response = $this->controller->report(
|
|
Request::create('POST', '/api/v1/kpis/open_tickets', body: ['value' => 'abc']),
|
|
['key' => 'open_tickets']
|
|
);
|
|
|
|
self::assertSame(422, $response->status);
|
|
}
|
|
|
|
public function testReportReturns201WithKpi(): void
|
|
{
|
|
$response = $this->controller->report(
|
|
Request::create('POST', '/api/v1/kpis/open_tickets', body: ['value' => 3]),
|
|
['key' => 'open_tickets']
|
|
);
|
|
|
|
self::assertSame(201, $response->status);
|
|
self::assertSame(3.0, $response->body()['kpi']['current_value']);
|
|
}
|
|
|
|
public function testIndexListsKpis(): void
|
|
{
|
|
$this->controller->report(Request::create('POST', '/x', body: ['value' => 1]), ['key' => 'a']);
|
|
|
|
$response = $this->controller->index(Request::create('GET', '/api/v1/kpis'));
|
|
|
|
self::assertCount(1, $response->body()['kpis']);
|
|
}
|
|
}
|