Wire ProjectZomboidDetective with all 11 log classes
Constructor pre-registers every concrete ProjectZomboid Log subclass so that detect() can dispatch on filename hint plus content signature. Data-provider test verifies each of the eleven synthetic fixtures resolves to its expected Log class via the public Detective surface.
This commit is contained in:
@@ -3,8 +3,36 @@
|
||||
namespace IndifferentKetchup\Codex\Detective\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Detective\Detective;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidAdminLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidBurdJournalsLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidChatLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidClientActionLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidCmdLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidItemLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidMapLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidPerkLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidPvpLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidServerLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidUserLog;
|
||||
|
||||
/**
|
||||
* Pre-registers all eleven ProjectZomboid log classes so that detect()
|
||||
* can dispatch among them on filename hint + content signature.
|
||||
*/
|
||||
class ProjectZomboidDetective extends Detective
|
||||
{
|
||||
// TODO: implement game-specific log type detection
|
||||
public function __construct()
|
||||
{
|
||||
$this->addPossibleLogClass(ProjectZomboidServerLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidChatLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidClientActionLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidCmdLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidItemLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidMapLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidPerkLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidPvpLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidAdminLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidUserLog::class);
|
||||
$this->addPossibleLogClass(ProjectZomboidBurdJournalsLog::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Detective;
|
||||
|
||||
use IndifferentKetchup\Codex\Detective\ProjectZomboid\ProjectZomboidDetective;
|
||||
use IndifferentKetchup\Codex\Log\File\PathLogFile;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidAdminLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidBurdJournalsLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidChatLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidClientActionLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidCmdLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidItemLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidMapLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidPerkLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidPvpLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidServerLog;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidUserLog;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ProjectZomboidDetectiveTest extends TestCase
|
||||
{
|
||||
private function fixturesDir(): string
|
||||
{
|
||||
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{string, class-string}>
|
||||
*/
|
||||
public static function fixtureDispatchProvider(): array
|
||||
{
|
||||
return [
|
||||
'server' => ['debug-server-minimal.txt', ProjectZomboidServerLog::class],
|
||||
'chat' => ['chat-minimal.txt', ProjectZomboidChatLog::class],
|
||||
'client-action' => ['client-action-minimal.txt', ProjectZomboidClientActionLog::class],
|
||||
'cmd' => ['cmd-minimal.txt', ProjectZomboidCmdLog::class],
|
||||
'item' => ['item-minimal.txt', ProjectZomboidItemLog::class],
|
||||
'map' => ['map-minimal.txt', ProjectZomboidMapLog::class],
|
||||
'perk' => ['perk-minimal.txt', ProjectZomboidPerkLog::class],
|
||||
'pvp' => ['pvp-minimal.txt', ProjectZomboidPvpLog::class],
|
||||
'admin' => ['admin-minimal.txt', ProjectZomboidAdminLog::class],
|
||||
'user' => ['user-minimal.txt', ProjectZomboidUserLog::class],
|
||||
'burd-journals' => ['burd-journals-minimal.txt', ProjectZomboidBurdJournalsLog::class],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('fixtureDispatchProvider')]
|
||||
public function testDispatchesEachFixtureToCorrectLogClass(string $fixture, string $expectedClass): void
|
||||
{
|
||||
$detective = (new ProjectZomboidDetective())
|
||||
->setLogFile(new PathLogFile($this->fixturesDir() . $fixture));
|
||||
|
||||
$this->assertInstanceOf($expectedClass, $detective->detect());
|
||||
}
|
||||
|
||||
public function testRegistersElevenLogClasses(): void
|
||||
{
|
||||
$detective = new ProjectZomboidDetective();
|
||||
$this->assertCount(11, $detective->getPossibleLogClasses());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user