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:
47
test/tests/Detective/FilenameDetectorTest.php
Normal file
47
test/tests/Detective/FilenameDetectorTest.php
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user