Add ModLoadInformation insight
This commit is contained in:
21
src/Analysis/ProjectZomboid/ModLoadInformation.php
Normal file
21
src/Analysis/ProjectZomboid/ModLoadInformation.php
Normal 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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user