Add ModMissingProblem and ModMissingSolution
This commit is contained in:
39
src/Analysis/ProjectZomboid/ModMissingProblem.php
Normal file
39
src/Analysis/ProjectZomboid/ModMissingProblem.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Analysis\InsightInterface;
|
||||
use IndifferentKetchup\Codex\Analysis\PatternInsightInterface;
|
||||
use IndifferentKetchup\Codex\Analysis\Problem;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\DebugServerPattern;
|
||||
|
||||
class ModMissingProblem extends Problem implements PatternInsightInterface
|
||||
{
|
||||
private string $modName = '';
|
||||
|
||||
public static function getPatterns(): array
|
||||
{
|
||||
return [DebugServerPattern::MOD_MISSING];
|
||||
}
|
||||
|
||||
public function setMatches(array $matches, mixed $patternKey): void
|
||||
{
|
||||
$this->modName = $matches['mod'];
|
||||
$this->addSolution((new ModMissingSolution())->setModName($this->modName));
|
||||
}
|
||||
|
||||
public function getModName(): string
|
||||
{
|
||||
return $this->modName;
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return sprintf('Required mod "%s" not found.', $this->modName);
|
||||
}
|
||||
|
||||
public function isEqual(InsightInterface $insight): bool
|
||||
{
|
||||
return $insight instanceof self && $insight->getModName() === $this->modName;
|
||||
}
|
||||
}
|
||||
24
src/Analysis/ProjectZomboid/ModMissingSolution.php
Normal file
24
src/Analysis/ProjectZomboid/ModMissingSolution.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Analysis\Solution;
|
||||
|
||||
class ModMissingSolution extends Solution
|
||||
{
|
||||
private string $modName = '';
|
||||
|
||||
public function setModName(string $modName): static
|
||||
{
|
||||
$this->modName = $modName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return sprintf(
|
||||
'Subscribe to mod "%s" or remove its ID from the Mods= line in serverconfig.ini.',
|
||||
$this->modName
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Analysis;
|
||||
|
||||
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\ModMissingProblem;
|
||||
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\ModMissingSolution;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\DebugServerPattern;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ModMissingProblemTest extends TestCase
|
||||
{
|
||||
public function testGetPatternsReturnsTheModMissingRegex(): void
|
||||
{
|
||||
$this->assertSame([DebugServerPattern::MOD_MISSING], ModMissingProblem::getPatterns());
|
||||
}
|
||||
|
||||
public function testSetMatchesExtractsModNameAndAttachesSolution(): void
|
||||
{
|
||||
$line = '[16-04-26 00:01:19.200] WARN : Mod f:0, t:1776297679200, st:48,648,194,378> ZomboidFileSystem.loadModAndRequired> required mod "absent_mod" not found.';
|
||||
$this->assertSame(1, preg_match(DebugServerPattern::MOD_MISSING, $line, $matches));
|
||||
|
||||
$problem = new ModMissingProblem();
|
||||
$problem->setMatches($matches, 0);
|
||||
|
||||
$this->assertSame('absent_mod', $problem->getModName());
|
||||
$this->assertStringContainsString('absent_mod', $problem->getMessage());
|
||||
$this->assertCount(1, $problem->getSolutions());
|
||||
|
||||
$solution = $problem->getSolutions()[0];
|
||||
$this->assertInstanceOf(ModMissingSolution::class, $solution);
|
||||
$this->assertStringContainsString('absent_mod', $solution->getMessage());
|
||||
$this->assertStringContainsString('serverconfig.ini', $solution->getMessage());
|
||||
}
|
||||
|
||||
public function testIsEqualCoalescesSameMissingMod(): void
|
||||
{
|
||||
$a = $this->problemFor('mod_x');
|
||||
$b = $this->problemFor('mod_x');
|
||||
$c = $this->problemFor('mod_y');
|
||||
|
||||
$this->assertTrue($a->isEqual($b));
|
||||
$this->assertFalse($a->isEqual($c));
|
||||
}
|
||||
|
||||
private function problemFor(string $modName): ModMissingProblem
|
||||
{
|
||||
$problem = new ModMissingProblem();
|
||||
$problem->setMatches(['mod' => $modName], 0);
|
||||
return $problem;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user