Files
ik-codex/test/tests/Games/ProjectZomboid/Log/ProjectZomboidChatLogTest.php
indifferentketchup 28e8fc8dc6 Add ProjectZomboidChatLog (chat.txt)
Handles both chat-engine events (bracketed level prefix) and bare
server-alert lines via an optional level group. Detectors: filename
match on _chat.txt plus content signatures for ChatMessage{...} log
entries and the chat-server initialization banner. CHAT_MESSAGE and
SERVER_ALERT named-group regexes ride along on ChatPattern for analyser
extraction in phase B.
2026-04-30 20:34:50 +00:00

54 lines
1.7 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\ProjectZomboidChatLog;
use PHPUnit\Framework\TestCase;
class ProjectZomboidChatLogTest extends TestCase
{
private function fixturePath(): string
{
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/chat-minimal.txt';
}
public function testParsesEachLineAsAnEntry(): void
{
$log = (new ProjectZomboidChatLog())->setLogFile(new PathLogFile($this->fixturePath()));
$log->parse();
$this->assertCount(13, $log->getEntries());
}
public function testInfoBracketIsParsedAsLevel(): void
{
$log = (new ProjectZomboidChatLog())->setLogFile(new PathLogFile($this->fixturePath()));
$log->parse();
$first = $log->getEntries()[0];
$this->assertSame(Level::INFO, $first->getLevel());
$this->assertNotNull($first->getTime());
}
public function testServerAlertLinesParseWithoutLevel(): void
{
$log = (new ProjectZomboidChatLog())->setLogFile(new PathLogFile($this->fixturePath()));
$log->parse();
$alert = $log->getEntries()[10];
$this->assertStringContainsString('Server alert message', (string) $alert);
}
public function testDetectiveDispatchesByContent(): void
{
$detective = (new Detective())
->setLogFile(new PathLogFile($this->fixturePath()))
->addPossibleLogClass(ProjectZomboidChatLog::class);
$this->assertInstanceOf(ProjectZomboidChatLog::class, $detective->detect());
}
}