Add ModLoadInformation insight

This commit is contained in:
2026-04-30 21:31:33 +00:00
parent 11efa66494
commit 4be6ebac10
2 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<?php
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
use IndifferentKetchup\Codex\Analysis\Information;
use IndifferentKetchup\Codex\Analysis\PatternInsightInterface;
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\DebugServerPattern;
class ModLoadInformation extends Information implements PatternInsightInterface
{
public static function getPatterns(): array
{
return [DebugServerPattern::MOD_LOAD];
}
public function setMatches(array $matches, mixed $patternKey): void
{
$this->setLabel('Mod loaded');
$this->setValue($matches['mod']);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Analysis;
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\ModLoadInformation;
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\DebugServerPattern;
use PHPUnit\Framework\TestCase;
class ModLoadInformationTest extends TestCase
{
public function testGetPatternsReturnsTheModLoadRegex(): void
{
$this->assertSame([DebugServerPattern::MOD_LOAD], ModLoadInformation::getPatterns());
}
public function testSetMatchesExtractsModName(): void
{
$line = '[16-04-26 00:01:19.131] LOG : Mod f:0, t:1776297679131, st:48,648,194,309> loading example_mod_alpha.';
$this->assertSame(1, preg_match(DebugServerPattern::MOD_LOAD, $line, $matches));
$insight = new ModLoadInformation();
$insight->setMatches($matches, 0);
$this->assertSame('Mod loaded', $insight->getLabel());
$this->assertSame('example_mod_alpha', $insight->getValue());
}
public function testIsEqualCoalescesSameMod(): void
{
$a = $this->insightFor('example_mod_alpha');
$b = $this->insightFor('example_mod_alpha');
$c = $this->insightFor('example_mod_beta');
$this->assertTrue($a->isEqual($b));
$this->assertFalse($a->isEqual($c));
}
private function insightFor(string $modName): ModLoadInformation
{
$insight = new ModLoadInformation();
$insight->setMatches(['mod' => $modName], 0);
return $insight;
}
}