Initial import from aternosorg/codex-minecraft
This commit is contained in:
13
test/src/Analysis/TestInformation.php
Normal file
13
test/src/Analysis/TestInformation.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Analysis;
|
||||
|
||||
use Aternos\Codex\Analysis\Information;
|
||||
|
||||
/**
|
||||
* Class TestInformation
|
||||
*/
|
||||
class TestInformation extends Information
|
||||
{
|
||||
protected ?string $label = "Label";
|
||||
}
|
||||
33
test/src/Analysis/TestInsight.php
Normal file
33
test/src/Analysis/TestInsight.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Analysis;
|
||||
|
||||
use Aternos\Codex\Analysis\Insight;
|
||||
use Aternos\Codex\Analysis\InsightInterface;
|
||||
|
||||
/**
|
||||
* Class TestInsight
|
||||
*/
|
||||
class TestInsight extends Insight
|
||||
{
|
||||
/**
|
||||
* Get the insight as human-readable message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(): string
|
||||
{
|
||||
return "This is a test insight";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the $insight object is equal with the current object
|
||||
*
|
||||
* @param InsightInterface $insight
|
||||
* @return bool
|
||||
*/
|
||||
public function isEqual(InsightInterface $insight): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
43
test/src/Analysis/TestPatternInformation.php
Normal file
43
test/src/Analysis/TestPatternInformation.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Analysis;
|
||||
|
||||
use Aternos\Codex\Analysis\Information;
|
||||
use Aternos\Codex\Analysis\PatternInsightInterface;
|
||||
|
||||
/**
|
||||
* Class TestPatternInformation
|
||||
*/
|
||||
class TestPatternInformation extends Information implements PatternInsightInterface
|
||||
{
|
||||
protected ?string $label = "Software version";
|
||||
|
||||
/**
|
||||
* Get an array of possible patterns
|
||||
*
|
||||
* The array key of the pattern will be passed to setMatches()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPatterns(): array
|
||||
{
|
||||
return ['/This log was generated by software (v[0-9\.]*)/'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the matches from the pattern
|
||||
*
|
||||
* @param array $matches
|
||||
* @param mixed $patternKey
|
||||
* @return void
|
||||
*/
|
||||
public function setMatches(array $matches, mixed $patternKey): void
|
||||
{
|
||||
$this->value = $matches[1];
|
||||
}
|
||||
|
||||
public function getLogContent(): ?string
|
||||
{
|
||||
return parent::getLogContent();
|
||||
}
|
||||
}
|
||||
70
test/src/Analysis/TestPatternProblem.php
Normal file
70
test/src/Analysis/TestPatternProblem.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Analysis;
|
||||
|
||||
use Aternos\Codex\Analysis\InsightInterface;
|
||||
use Aternos\Codex\Analysis\PatternInsightInterface;
|
||||
use Aternos\Codex\Analysis\Problem;
|
||||
|
||||
/**
|
||||
* Class TestPatternProblem
|
||||
*/
|
||||
class TestPatternProblem extends Problem implements PatternInsightInterface
|
||||
{
|
||||
protected ?string $cause = null;
|
||||
|
||||
/**
|
||||
* @param string $cause
|
||||
* @return TestPatternProblem
|
||||
*/
|
||||
public function setCause(string $cause): static
|
||||
{
|
||||
$this->cause = $cause;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of possible patterns
|
||||
*
|
||||
* The array key of the pattern will be passed to setMatches()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPatterns(): array
|
||||
{
|
||||
return ['/I have a problem with (\w+)/'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the matches from the pattern
|
||||
*
|
||||
* @param array $matches
|
||||
* @param mixed $patternKey
|
||||
* @return void
|
||||
*/
|
||||
public function setMatches(array $matches, mixed $patternKey): void
|
||||
{
|
||||
$this->cause = $matches[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the problem as human-readable message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(): string
|
||||
{
|
||||
return "There is a problem with " . $this->cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the $insight object is equal with the current object
|
||||
*
|
||||
* @param InsightInterface $insight
|
||||
* @return bool
|
||||
*/
|
||||
public function isEqual(InsightInterface $insight): bool
|
||||
{
|
||||
return $insight instanceof static && $this->cause === $insight->cause;
|
||||
}
|
||||
}
|
||||
33
test/src/Analysis/TestProblem.php
Normal file
33
test/src/Analysis/TestProblem.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Analysis;
|
||||
|
||||
use Aternos\Codex\Analysis\InsightInterface;
|
||||
use Aternos\Codex\Analysis\Problem;
|
||||
|
||||
/**
|
||||
* Class TestProblem
|
||||
*/
|
||||
class TestProblem extends Problem
|
||||
{
|
||||
/**
|
||||
* Get the problem as human-readable message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(): string
|
||||
{
|
||||
return "This is a test problem";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the $insight object is equal with the current object
|
||||
*
|
||||
* @param InsightInterface $insight
|
||||
* @return bool
|
||||
*/
|
||||
public function isEqual(InsightInterface $insight): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
21
test/src/Analysis/TestSolution.php
Normal file
21
test/src/Analysis/TestSolution.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Analysis;
|
||||
|
||||
use Aternos\Codex\Analysis\Solution;
|
||||
|
||||
/**
|
||||
* Class TestSolution
|
||||
*/
|
||||
class TestSolution extends Solution
|
||||
{
|
||||
/**
|
||||
* Get the solution as a human-readable message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(): string
|
||||
{
|
||||
return "This is a test solution.";
|
||||
}
|
||||
}
|
||||
24
test/src/Log/TestAlwaysDetectableLog.php
Normal file
24
test/src/Log/TestAlwaysDetectableLog.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Log;
|
||||
|
||||
use Aternos\Codex\Detective\DetectorInterface;
|
||||
use Aternos\Codex\Detective\SinglePatternDetector;
|
||||
use Aternos\Codex\Log\DetectableLogInterface;
|
||||
use Aternos\Codex\Log\Log;
|
||||
|
||||
/**
|
||||
* Class TestAlwaysDetectableLog
|
||||
*/
|
||||
class TestAlwaysDetectableLog extends Log implements DetectableLogInterface
|
||||
{
|
||||
/**
|
||||
* Get an array of detectors matching DetectorInterface
|
||||
*
|
||||
* @return DetectorInterface[]
|
||||
*/
|
||||
public static function getDetectors(): array
|
||||
{
|
||||
return [(new SinglePatternDetector())->setPattern('/information/')];
|
||||
}
|
||||
}
|
||||
24
test/src/Log/TestLessDetectableLog.php
Normal file
24
test/src/Log/TestLessDetectableLog.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Log;
|
||||
|
||||
use Aternos\Codex\Detective\DetectorInterface;
|
||||
use Aternos\Codex\Detective\LinePatternDetector;
|
||||
use Aternos\Codex\Log\DetectableLogInterface;
|
||||
use Aternos\Codex\Log\Log;
|
||||
|
||||
/**
|
||||
* Class TestLessDetectableLog
|
||||
*/
|
||||
class TestLessDetectableLog extends Log implements DetectableLogInterface
|
||||
{
|
||||
/**
|
||||
* Get an array of detectors matching DetectorInterface
|
||||
*
|
||||
* @return DetectorInterface[]
|
||||
*/
|
||||
public static function getDetectors(): array
|
||||
{
|
||||
return [(new LinePatternDetector())->setPattern('/information/')];
|
||||
}
|
||||
}
|
||||
24
test/src/Log/TestMoreDetectableLog.php
Normal file
24
test/src/Log/TestMoreDetectableLog.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Log;
|
||||
|
||||
use Aternos\Codex\Detective\DetectorInterface;
|
||||
use Aternos\Codex\Detective\LinePatternDetector;
|
||||
use Aternos\Codex\Log\DetectableLogInterface;
|
||||
use Aternos\Codex\Log\Log;
|
||||
|
||||
/**
|
||||
* Class TestMoreDetectableLog
|
||||
*/
|
||||
class TestMoreDetectableLog extends Log implements DetectableLogInterface
|
||||
{
|
||||
/**
|
||||
* Get an array of detectors matching DetectorInterface
|
||||
*
|
||||
* @return DetectorInterface[]
|
||||
*/
|
||||
public static function getDetectors(): array
|
||||
{
|
||||
return [(new LinePatternDetector())->setPattern('/This/')];
|
||||
}
|
||||
}
|
||||
24
test/src/Log/TestNeverDetectableLog.php
Normal file
24
test/src/Log/TestNeverDetectableLog.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Log;
|
||||
|
||||
use Aternos\Codex\Detective\DetectorInterface;
|
||||
use Aternos\Codex\Detective\SinglePatternDetector;
|
||||
use Aternos\Codex\Log\DetectableLogInterface;
|
||||
use Aternos\Codex\Log\Log;
|
||||
|
||||
/**
|
||||
* Class TestNeverDetectableLog
|
||||
*/
|
||||
class TestNeverDetectableLog extends Log implements DetectableLogInterface
|
||||
{
|
||||
/**
|
||||
* Get an array of detectors matching DetectorInterface
|
||||
*
|
||||
* @return DetectorInterface[]
|
||||
*/
|
||||
public static function getDetectors(): array
|
||||
{
|
||||
return [(new SinglePatternDetector())->setPattern('/missing/')];
|
||||
}
|
||||
}
|
||||
40
test/src/Log/TestPatternLog.php
Normal file
40
test/src/Log/TestPatternLog.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Log;
|
||||
|
||||
use Aternos\Codex\Analyser\PatternAnalyser;
|
||||
use Aternos\Codex\Log\AnalysableLog;
|
||||
use Aternos\Codex\Parser\PatternParser;
|
||||
use Aternos\Codex\Test\Src\Analysis\TestPatternInformation;
|
||||
use Aternos\Codex\Test\Src\Analysis\TestPatternProblem;
|
||||
|
||||
/**
|
||||
* Class TestLog
|
||||
*/
|
||||
class TestPatternLog extends AnalysableLog
|
||||
{
|
||||
/**
|
||||
* Get the default parser
|
||||
*
|
||||
* @return PatternParser
|
||||
*/
|
||||
public static function getDefaultParser(): PatternParser
|
||||
{
|
||||
return (new PatternParser())
|
||||
->setPattern('/(\[([^\]]+)\] \[[^\/]+\/([^\]]+)\]).*/')
|
||||
->setMatches([PatternParser::PREFIX, PatternParser::TIME, PatternParser::LEVEL])
|
||||
->setTimeFormat('d.m.Y H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default analyser
|
||||
*
|
||||
* @return PatternAnalyser
|
||||
*/
|
||||
public static function getDefaultAnalyser(): PatternAnalyser
|
||||
{
|
||||
return (new PatternAnalyser())
|
||||
->addPossibleInsightClass(TestPatternProblem::class)
|
||||
->addPossibleInsightClass(TestPatternInformation::class);
|
||||
}
|
||||
}
|
||||
22
test/src/Printer/TestModification.php
Normal file
22
test/src/Printer/TestModification.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Src\Printer;
|
||||
|
||||
use Aternos\Codex\Printer\Modification;
|
||||
|
||||
/**
|
||||
* Class TestModification
|
||||
*/
|
||||
class TestModification extends Modification
|
||||
{
|
||||
/**
|
||||
* Modify the given string and return it
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public function modify(string $text): string
|
||||
{
|
||||
return str_replace("foo", "bar", $text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user