Wire ProjectZomboidAdminLog default analyser
This commit is contained in:
@@ -4,6 +4,12 @@ namespace IndifferentKetchup\Codex\Log\ProjectZomboid;
|
|||||||
|
|
||||||
use IndifferentKetchup\Codex\Analyser\AnalyserInterface;
|
use IndifferentKetchup\Codex\Analyser\AnalyserInterface;
|
||||||
use IndifferentKetchup\Codex\Analyser\PatternAnalyser;
|
use IndifferentKetchup\Codex\Analyser\PatternAnalyser;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminAddedItemInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminAddedXpInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminChangedOptionInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminGrantedAccessInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminReloadedOptionsInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminTeleportedInformation;
|
||||||
use IndifferentKetchup\Codex\Detective\FilenameDetector;
|
use IndifferentKetchup\Codex\Detective\FilenameDetector;
|
||||||
use IndifferentKetchup\Codex\Detective\WeightedSinglePatternDetector;
|
use IndifferentKetchup\Codex\Detective\WeightedSinglePatternDetector;
|
||||||
use IndifferentKetchup\Codex\Parser\ParserInterface;
|
use IndifferentKetchup\Codex\Parser\ParserInterface;
|
||||||
@@ -22,7 +28,13 @@ class ProjectZomboidAdminLog extends ProjectZomboidEventLog
|
|||||||
|
|
||||||
public static function getDefaultAnalyser(): AnalyserInterface
|
public static function getDefaultAnalyser(): AnalyserInterface
|
||||||
{
|
{
|
||||||
return new PatternAnalyser();
|
return (new PatternAnalyser())
|
||||||
|
->addPossibleInsightClass(AdminAddedItemInformation::class)
|
||||||
|
->addPossibleInsightClass(AdminAddedXpInformation::class)
|
||||||
|
->addPossibleInsightClass(AdminGrantedAccessInformation::class)
|
||||||
|
->addPossibleInsightClass(AdminChangedOptionInformation::class)
|
||||||
|
->addPossibleInsightClass(AdminReloadedOptionsInformation::class)
|
||||||
|
->addPossibleInsightClass(AdminTeleportedInformation::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDetectors(): array
|
public static function getDetectors(): array
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Analyser;
|
||||||
|
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminAddedItemInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminAddedXpInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminChangedOptionInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminGrantedAccessInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminReloadedOptionsInformation;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminTeleportedInformation;
|
||||||
|
use IndifferentKetchup\Codex\Log\File\PathLogFile;
|
||||||
|
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidAdminLog;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AdminLogAnalysisTest extends TestCase
|
||||||
|
{
|
||||||
|
private function fixturePath(): string
|
||||||
|
{
|
||||||
|
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/admin-minimal.txt';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAnalyseProducesExpectedInsightCounts(): void
|
||||||
|
{
|
||||||
|
$log = (new ProjectZomboidAdminLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
||||||
|
$log->parse();
|
||||||
|
$analysis = $log->analyse();
|
||||||
|
|
||||||
|
$this->assertCount(2, $analysis->getFilteredInsights(AdminAddedItemInformation::class));
|
||||||
|
$this->assertCount(2, $analysis->getFilteredInsights(AdminAddedXpInformation::class));
|
||||||
|
$this->assertCount(2, $analysis->getFilteredInsights(AdminGrantedAccessInformation::class));
|
||||||
|
$this->assertCount(2, $analysis->getFilteredInsights(AdminChangedOptionInformation::class));
|
||||||
|
$this->assertCount(1, $analysis->getFilteredInsights(AdminReloadedOptionsInformation::class));
|
||||||
|
$this->assertCount(2, $analysis->getFilteredInsights(AdminTeleportedInformation::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIdenticalAddedItemEventsAreCoalesced(): void
|
||||||
|
{
|
||||||
|
$log = (new ProjectZomboidAdminLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
||||||
|
$log->parse();
|
||||||
|
$analysis = $log->analyse();
|
||||||
|
|
||||||
|
$shotgunInsight = null;
|
||||||
|
foreach ($analysis->getFilteredInsights(AdminAddedItemInformation::class) as $insight) {
|
||||||
|
if (str_contains($insight->getValue(), 'Base.ShotgunShells')) {
|
||||||
|
$shotgunInsight = $insight;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertNotNull($shotgunInsight);
|
||||||
|
$this->assertSame(2, $shotgunInsight->getCounterValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user