Add AdminChangedOptionInformation insight
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Analysis\Information;
|
||||
use IndifferentKetchup\Codex\Analysis\PatternInsightInterface;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||
|
||||
class AdminChangedOptionInformation extends Information implements PatternInsightInterface
|
||||
{
|
||||
public static function getPatterns(): array
|
||||
{
|
||||
return [AdminPattern::CHANGED_OPTION_ENTRY];
|
||||
}
|
||||
|
||||
public function setMatches(array $matches, mixed $patternKey): void
|
||||
{
|
||||
$this->setLabel('Admin changed option');
|
||||
$this->setValue(sprintf(
|
||||
'%s set %s=%s',
|
||||
$matches['admin'],
|
||||
$matches['option'],
|
||||
$matches['value']
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -38,4 +38,6 @@ class AdminPattern
|
||||
public const string ADDED_XP_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) added (?<amount>[\d.]+) (?<skill>\S+) xp\'s to (?<target>.+?)\.?$/';
|
||||
|
||||
public const string GRANTED_ACCESS_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) granted (?<level>\w+) access level on (?<target>.+?)\.?$/';
|
||||
|
||||
public const string CHANGED_OPTION_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) changed option (?<option>\S+?)=(?<value>.+?)\.?$/';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Analysis;
|
||||
|
||||
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminChangedOptionInformation;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AdminChangedOptionInformationTest extends TestCase
|
||||
{
|
||||
public function testGetPatternsReturnsEntryRegex(): void
|
||||
{
|
||||
$this->assertSame([AdminPattern::CHANGED_OPTION_ENTRY], AdminChangedOptionInformation::getPatterns());
|
||||
}
|
||||
|
||||
public function testEntryRegexMatchesFullLine(): void
|
||||
{
|
||||
$line = "[16-04-26 18:36:15.500] AdminUser changed option AnnounceDeath=true.";
|
||||
$this->assertSame(1, preg_match(AdminPattern::CHANGED_OPTION_ENTRY, $line, $m));
|
||||
|
||||
$insight = new AdminChangedOptionInformation();
|
||||
$insight->setMatches($m, 0);
|
||||
|
||||
$this->assertSame('Admin changed option', $insight->getLabel());
|
||||
$this->assertSame('AdminUser set AnnounceDeath=true', $insight->getValue());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user