From cca5208cc096ff0ffcba99d6b8d7f6b9d305964f Mon Sep 17 00:00:00 2001 From: indifferentketchup Date: Thu, 30 Apr 2026 20:43:51 +0000 Subject: [PATCH] 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. --- .../ProjectZomboidDetective.php | 30 ++++++++- .../Detective/ProjectZomboidDetectiveTest.php | 62 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/tests/Games/ProjectZomboid/Detective/ProjectZomboidDetectiveTest.php diff --git a/src/Detective/ProjectZomboid/ProjectZomboidDetective.php b/src/Detective/ProjectZomboid/ProjectZomboidDetective.php index b2be260..dcdc2fa 100644 --- a/src/Detective/ProjectZomboid/ProjectZomboidDetective.php +++ b/src/Detective/ProjectZomboid/ProjectZomboidDetective.php @@ -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); + } } diff --git a/test/tests/Games/ProjectZomboid/Detective/ProjectZomboidDetectiveTest.php b/test/tests/Games/ProjectZomboid/Detective/ProjectZomboidDetectiveTest.php new file mode 100644 index 0000000..90cbb6b --- /dev/null +++ b/test/tests/Games/ProjectZomboid/Detective/ProjectZomboidDetectiveTest.php @@ -0,0 +1,62 @@ + + */ + 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()); + } +}