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>
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Monitor\Api\Tests\Repository;
|
|
|
|
use Monitor\Api\Repository\LegacyStatusFileReader;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class LegacyStatusFileReaderTest extends TestCase
|
|
{
|
|
private string $tmpFile;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->tmpFile = tempnam(sys_get_temp_dir(), 'status_');
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
if (is_file($this->tmpFile)) {
|
|
unlink($this->tmpFile);
|
|
}
|
|
}
|
|
|
|
public function testReadsValidLines(): void
|
|
{
|
|
file_put_contents($this->tmpFile, "Server1 192.168.178.2 online 2026-07-27 10:00\nServer2 192.168.178.3 offline 2026-07-27 10:01\n");
|
|
|
|
$rows = (new LegacyStatusFileReader())->read($this->tmpFile);
|
|
|
|
self::assertCount(2, $rows);
|
|
self::assertSame('Server1', $rows[0]['id']);
|
|
self::assertSame('ok', $rows[0]['status']);
|
|
self::assertSame('192.168.178.2', $rows[0]['detail']);
|
|
self::assertSame('2026-07-27 10:00', $rows[0]['last_check_at']);
|
|
self::assertSame('error', $rows[1]['status']);
|
|
}
|
|
|
|
public function testSkipsMalformedLines(): void
|
|
{
|
|
file_put_contents($this->tmpFile, "incomplete line\nServer1 1.2.3.4 online 2026-07-27 10:00\n");
|
|
|
|
$rows = (new LegacyStatusFileReader())->read($this->tmpFile);
|
|
|
|
self::assertCount(1, $rows);
|
|
}
|
|
|
|
public function testReturnsEmptyArrayForMissingFile(): void
|
|
{
|
|
self::assertSame([], (new LegacyStatusFileReader())->read('/does/not/exist.txt'));
|
|
}
|
|
}
|