Add EngineVersionInformation insight

This commit is contained in:
2026-04-30 21:31:01 +00:00
parent e45fd85665
commit 11efa66494
2 changed files with 55 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
use IndifferentKetchup\Codex\Analysis\Information;
use IndifferentKetchup\Codex\Analysis\PatternInsightInterface;
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\DebugServerPattern;
class EngineVersionInformation extends Information implements PatternInsightInterface
{
public static function getPatterns(): array
{
return [DebugServerPattern::VERSION];
}
public function setMatches(array $matches, mixed $patternKey): void
{
$this->setLabel('Engine version');
$this->setValue(sprintf(
'%s (build %s, %s %s)',
$matches['version'],
$matches['hash'],
$matches['date'],
$matches['time']
));
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Analysis;
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\EngineVersionInformation;
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\DebugServerPattern;
use PHPUnit\Framework\TestCase;
class EngineVersionInformationTest extends TestCase
{
public function testGetPatternsReturnsTheVersionRegex(): void
{
$this->assertSame([DebugServerPattern::VERSION], EngineVersionInformation::getPatterns());
}
public function testSetMatchesPopulatesLabelAndValue(): void
{
$line = '[16-04-26 00:00:42.407] LOG : General f:0, t:1776297642406, st:48,648,157,584> version=42.16.3 0000000000000000000000000000000000000000 2026-04-08 11:54:01 (ZB) demo=false.';
$this->assertSame(1, preg_match(DebugServerPattern::VERSION, $line, $matches));
$insight = new EngineVersionInformation();
$insight->setMatches($matches, 0);
$this->assertSame('Engine version', $insight->getLabel());
$this->assertSame('42.16.3 (build 0000000000000000000000000000000000000000, 2026-04-08 11:54:01)', $insight->getValue());
$this->assertSame('Engine version: 42.16.3 (build 0000000000000000000000000000000000000000, 2026-04-08 11:54:01)', $insight->getMessage());
}
}