Files
ik-codex/test/tests/Games/ProjectZomboid/Log/ProjectZomboidUserLogTest.php
indifferentketchup d7c36ffc07 Add ProjectZomboidUserLog (user.txt)
Two row variants: low-level Connection events and player join/disconnect
events. The LINE regex accepts both shapes; analysers route via
CONNECTION (action/index/guid/id) and PLAYER_EVENT (steamid/player/event)
named-group regexes. Detectors: filename match plus content signatures
on either variant.
2026-04-30 20:42:19 +00:00

59 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\ProjectZomboid\ProjectZomboidUserLog;
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\UserPattern;
use PHPUnit\Framework\TestCase;
class ProjectZomboidUserLogTest extends TestCase
{
private function fixturePath(): string
{
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/user-minimal.txt';
}
public function testParsesEachLineAsAnEntry(): void
{
$log = (new ProjectZomboidUserLog())->setLogFile(new PathLogFile($this->fixturePath()));
$log->parse();
$this->assertCount(9, $log->getEntries());
}
public function testConnectionRegexExtractsAddVariant(): void
{
$line = '[29-04-26 18:35:41.512] Connection add index=0 guid=144118788000000001 id=null.';
$this->assertSame(1, preg_match(UserPattern::CONNECTION, $line, $m));
$this->assertSame('add', $m['action']);
$this->assertSame('null', $m['id']);
}
public function testConnectionRegexExtractsDisconnectVariant(): void
{
$line = '[29-04-26 18:39:23.923] Connection disconnect index=0 guid=144118788000000001 id=76561198000000001.';
$this->assertSame(1, preg_match(UserPattern::CONNECTION, $line, $m));
$this->assertSame('disconnect', $m['action']);
$this->assertSame('76561198000000001', $m['id']);
}
public function testPlayerEventRegexExtracts(): void
{
$line = '[29-04-26 18:35:42.802] 76561198000000001 "Player1" attempting to join.';
$this->assertSame(1, preg_match(UserPattern::PLAYER_EVENT, $line, $m));
$this->assertSame('Player1', $m['player']);
$this->assertSame('attempting to join', $m['event']);
}
public function testDetectiveDispatchesByContent(): void
{
$detective = (new Detective())
->setLogFile(new PathLogFile($this->fixturePath()))
->addPossibleLogClass(ProjectZomboidUserLog::class);
$this->assertInstanceOf(ProjectZomboidUserLog::class, $detective->detect());
}
}