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.
63 lines
3.0 KiB
PHP
63 lines
3.0 KiB
PHP
<?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());
|
|
}
|
|
}
|