Add FilenameDetector for path-based log type dispatch

New Detector that matches a configured regex against
LogFileInterface::getPath(). Returns a settable weight on match (default
0.95) and false otherwise, including when the log file has no known path
(StringLogFile, StreamLogFile). Lets game-specific Detectives prefer the
filename hint over content signatures when an upload's original name is
preserved.
This commit is contained in:
2026-04-30 20:29:56 +00:00
parent 8ae7da5259
commit ada3c7875d
2 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace IndifferentKetchup\Codex\Test\Tests\Detective;
use IndifferentKetchup\Codex\Detective\FilenameDetector;
use IndifferentKetchup\Codex\Log\File\PathLogFile;
use IndifferentKetchup\Codex\Log\File\StringLogFile;
use PHPUnit\Framework\TestCase;
class FilenameDetectorTest extends TestCase
{
public function testReturnsWeightWhenPatternMatchesPath(): void
{
$detector = (new FilenameDetector())
->setPattern('/simple\.log$/')
->setWeight(0.9);
$detector->setLogFile(new PathLogFile(__DIR__ . "/../../data/simple.log"));
$this->assertSame(0.9, $detector->detect());
}
public function testReturnsFalseWhenPatternDoesNotMatch(): void
{
$detector = (new FilenameDetector())
->setPattern('/notthere\.txt$/');
$detector->setLogFile(new PathLogFile(__DIR__ . "/../../data/simple.log"));
$this->assertFalse($detector->detect());
}
public function testReturnsFalseWhenLogFileHasNoPath(): void
{
$detector = (new FilenameDetector())
->setPattern('/anything/');
$detector->setLogFile(new StringLogFile("content"));
$this->assertFalse($detector->detect());
}
public function testReturnsFalseWhenPatternUnset(): void
{
$detector = new FilenameDetector();
$detector->setLogFile(new PathLogFile(__DIR__ . "/../../data/simple.log"));
$this->assertFalse($detector->detect());
}
}