Sliding-window heuristic over (Steam ID, item code) groups: any window of THRESHOLD_WINDOW_SECONDS containing THRESHOLD_COUNT or more positive-delta events for the same player/item pair triggers a Problem. Negative deltas (drops, transfers out) are filtered. Five events in ten seconds (defaults) encodes the rule of thumb that legitimate gameplay rarely produces five identical items in that span. Constants live as class constants on the analyser so operators can override via subclass without touching analysis logic; the docblocks record the justification. Synthetic fixture extended with a 6-event burst (AdminUser + Base.Bullets9mm in <1s) and a 4-event sub-threshold group (Player1 + Base.Plank scattered over 4 minutes) to exercise both paths.
45 lines
1.6 KiB
PHP
45 lines
1.6 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\ProjectZomboidItemLog;
|
|
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\ItemPattern;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ProjectZomboidItemLogTest extends TestCase
|
|
{
|
|
private function fixturePath(): string
|
|
{
|
|
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/item-minimal.txt';
|
|
}
|
|
|
|
public function testParsesEachLineAsAnEntry(): void
|
|
{
|
|
$log = (new ProjectZomboidItemLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
|
$log->parse();
|
|
|
|
$this->assertCount(20, $log->getEntries());
|
|
}
|
|
|
|
public function testFieldsRegexExtractsItemAndDelta(): void
|
|
{
|
|
$line = '[16-04-26 19:42:25.223] 76561198000000002 "Player2" inventory +5 1011,2011,0 [Base.Bullets9mm].';
|
|
$this->assertSame(1, preg_match(ItemPattern::FIELDS, $line, $m));
|
|
$this->assertSame('Player2', $m['player']);
|
|
$this->assertSame('inventory', $m['location']);
|
|
$this->assertSame('+5', $m['delta']);
|
|
$this->assertSame('Base.Bullets9mm', $m['item']);
|
|
}
|
|
|
|
public function testDetectiveDispatchesByContent(): void
|
|
{
|
|
$detective = (new Detective())
|
|
->setLogFile(new PathLogFile($this->fixturePath()))
|
|
->addPossibleLogClass(ProjectZomboidItemLog::class);
|
|
|
|
$this->assertInstanceOf(ProjectZomboidItemLog::class, $detective->detect());
|
|
}
|
|
}
|