Files
ik-codex/test/tests/Games/ProjectZomboid/Log/ProjectZomboidServerLogTest.php
indifferentketchup d863fae9e6 Add ProjectZomboidServerLog (DebugLog-server.txt)
Concrete Log subclass for the engine debug log. Captures time, level,
and subsystem prefix per entry; stack-trace continuation lines attach
to the triggering ERROR entry via PatternParser's append-on-no-match
behaviour. Detectors: filename match on DebugLog-server.txt plus two
content signatures (the version=X.Y.Z+hash banner and the level/
subsystem/f/t/st header shape). Pattern constants live in
src/Pattern/ProjectZomboid/DebugServerPattern.php with named groups
ready for analyser use in phase B. Synthetic fixture under
test/src/Games/ProjectZomboid/fixtures/ uses zeroed identifiers and
placeholder paths.
2026-04-30 20:34:03 +00:00

68 lines
2.2 KiB
PHP

<?php
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Log;
use IndifferentKetchup\Codex\Detective\Detective;
use IndifferentKetchup\Codex\Log\File\PathLogFile;
use IndifferentKetchup\Codex\Log\Level;
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidServerLog;
use PHPUnit\Framework\TestCase;
class ProjectZomboidServerLogTest extends TestCase
{
private function fixturePath(): string
{
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/debug-server-minimal.txt';
}
public function testParsesEntriesWithLevelAndPrefix(): void
{
$log = (new ProjectZomboidServerLog())->setLogFile(new PathLogFile($this->fixturePath()));
$log->parse();
$entries = $log->getEntries();
$this->assertNotEmpty($entries);
$first = $entries[0];
$this->assertSame('General', $first->getPrefix());
$this->assertSame(Level::INFO, $first->getLevel());
$this->assertNotNull($first->getTime());
}
public function testStackTraceLinesAttachToTriggeringErrorEntry(): void
{
$log = (new ProjectZomboidServerLog())->setLogFile(new PathLogFile($this->fixturePath()));
$log->parse();
$errorEntry = null;
foreach ($log->getEntries() as $entry) {
if ($entry->getLevel() === Level::ERROR && $entry->getPrefix() === 'General') {
$errorEntry = $entry;
break;
}
}
$this->assertNotNull($errorEntry);
$this->assertGreaterThan(1, count($errorEntry->getLines()));
}
public function testWarnLevelMapsCorrectly(): void
{
$log = (new ProjectZomboidServerLog())->setLogFile(new PathLogFile($this->fixturePath()));
$log->parse();
$warnEntries = array_filter($log->getEntries(), fn($e) => $e->getLevel() === Level::WARNING);
$this->assertNotEmpty($warnEntries);
}
public function testDetectiveDispatchesByContent(): void
{
$detective = (new Detective())
->setLogFile(new PathLogFile($this->fixturePath()))
->addPossibleLogClass(ProjectZomboidServerLog::class);
$log = $detective->detect();
$this->assertInstanceOf(ProjectZomboidServerLog::class, $log);
}
}