Files
ik-codex/test/tests/Detective/FilenameDetectorTest.php
indifferentketchup ada3c7875d 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.
2026-04-30 20:29:56 +00:00

48 lines
1.4 KiB
PHP

<?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());
}
}