Initial import from aternosorg/codex-minecraft
Some checks failed
Tests / Run tests on PHP v8.4 (push) Failing after 32s
Tests / Run tests on PHP v8.5 (push) Failing after 2s

This commit is contained in:
2026-04-30 09:56:57 -05:00
commit 7c7fe5ca80
94 changed files with 7003 additions and 0 deletions

View File

@@ -0,0 +1,157 @@
<?php
namespace Aternos\Codex\Test\Tests\Analysis;
use Aternos\Codex\Analysis\Analysis;
use Aternos\Codex\Test\Src\Analysis\TestInformation;
use Aternos\Codex\Test\Src\Analysis\TestInsight;
use Aternos\Codex\Test\Src\Analysis\TestPatternProblem;
use Aternos\Codex\Test\Src\Analysis\TestProblem;
use PHPUnit\Framework\TestCase;
class AnalysisTest extends TestCase
{
public function testSetGetInsights(): void
{
$analysis = new Analysis();
$insight = new TestInsight();
$this->assertSame($analysis, $analysis->setInsights([$insight]));
$this->assertSame([$insight], $analysis->getInsights());
}
public function testAddInsight(): void
{
$analysis = new Analysis();
$insight = new TestInsight();
$this->assertSame($analysis, $analysis->addInsight($insight));
$this->assertSame([$insight], $analysis->getInsights());
}
public function testGetProblems(): void
{
$analysis = new Analysis();
$problem = new TestProblem();
$information = new TestInformation();
$analysis->addInsight($problem);
$analysis->addInsight($information);
$this->assertEquals([$problem], $analysis->getProblems());
}
public function testGetInformation(): void
{
$analysis = new Analysis();
$problem = new TestProblem();
$information = new TestInformation();
$analysis->addInsight($problem);
$analysis->addInsight($information);
$this->assertEquals([$information], $analysis->getInformation());
}
public function testKey(): void
{
$analysis = new Analysis();
$problem = new TestProblem();
$information = new TestInformation();
$analysis->addInsight($problem);
$this->assertEquals(0, $analysis->key());
$analysis->addInsight($information);
$this->assertEquals(1, $analysis->key());
}
public function testCount(): void
{
$analysis = new Analysis();
$problem = new TestProblem();
$information = new TestInformation();
$this->assertEquals(0, $analysis->count());
$analysis->addInsight($problem);
$this->assertEquals(1, $analysis->count());
$analysis->addInsight($information);
$this->assertEquals(2, $analysis->count());
}
public function testAddingTheSameInsightIncreasesInternalCounter(): void
{
// Adding the same insight to an analysis does not add it to the insights, and therefore it
// does not increase the counter of the analysis, but the internal counter of the insight.
// See Analysis->addInsight()
$analysis = new Analysis();
$problem = new TestPatternProblem();
$problem2 = new TestPatternProblem();
$analysis->addInsight($problem);
$this->assertEquals(1, $analysis->count());
$this->assertEquals(1, $problem->getCounterValue());
$analysis->addInsight($problem2);
$this->assertEquals(1, $analysis->count());
$this->assertEquals(2, $problem->getCounterValue());
}
public function testOffsetExists(): void
{
$analysis = new Analysis();
$information = new TestInformation();
$this->assertArrayNotHasKey(0, $analysis);
$this->assertEquals(0, $analysis->count());
$analysis->addInsight($information);
$this->assertArrayHasKey(0, $analysis);
$this->assertEquals($information, $analysis[0]);
}
public function testOffsetGet(): void
{
$analysis = new Analysis();
$information = new TestInformation();
$analysis->addInsight($information);
// Exists
$this->assertEquals($information, $analysis[0]);
// Does not exist -> "undefined array key" error
$this->assertArrayNotHasKey(1, $analysis);
}
public function testOffsetSet(): void
{
$analysis = new Analysis();
$information = new TestInformation();
$this->assertArrayNotHasKey(0, $analysis);
$this->assertEquals(0, $analysis->count());
$analysis->addInsight($information);
$this->assertArrayHasKey(0, $analysis);
$this->assertEquals($information, $analysis[0]);
// Overwrite $information on $analysis[0] using the offsetSet
$problem = new TestProblem();
$analysis[0] = $problem;
$this->assertEquals($problem, $analysis[0]);
}
public function testOffsetUnset(): void
{
$analysis = new Analysis();
$information = new TestInformation();
$this->assertArrayNotHasKey(0, $analysis);
$this->assertEquals(0, $analysis->count());
$analysis->addInsight($information);
$this->assertArrayHasKey(0, $analysis);
$this->assertEquals($information, $analysis[0]);
// Unset $information on $analysis[0] using the offsetUnset
unset($analysis[0]);
$this->assertArrayNotHasKey(0, $analysis);
$this->assertArrayNotHasKey(1, $analysis);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Aternos\Codex\Test\Tests\Analysis;
use Aternos\Codex\Log\File\PathLogFile;
use Aternos\Codex\Test\Src\Analysis\TestInformation;
use Aternos\Codex\Test\Src\Analysis\TestPatternInformation;
use Aternos\Codex\Test\Src\Log\TestPatternLog;
use PHPUnit\Framework\TestCase;
class InformationTest extends TestCase
{
public function testSetGetValue(): void
{
$value = uniqid();
$information = new TestInformation();
$information->setValue($value);
$this->assertEquals($value, $information->getValue());
}
public function testGetLabel(): void
{
$this->assertEquals("Label", (new TestInformation())->getLabel());
}
public function testGetMessage(): void
{
$value = uniqid();
$information = new TestInformation();
$information->setValue($value);
$this->assertEquals("Label: " . $value, $information->getMessage());
$this->assertEquals("Label: " . $value, (string)$information);
}
public function testIsEqual(): void
{
$value = uniqid();
$informationA = new TestInformation();
$informationA->setValue($value);
$informationB = new TestInformation();
$informationB->setValue($value);
$this->assertTrue($informationA->isEqual($informationB));
$this->assertTrue($informationA->isEqual($informationA));
}
public function testGetLogContent(): void
{
$logFile = new PathLogFile(__DIR__ . '/../../data/problem.log');
$log = (new TestPatternLog())->setLogFile($logFile);
$log->parse();
$analysis = $log->analyse();
foreach ($analysis->getInformation() as $information) {
/** @var TestPatternInformation $information */
$this->assertNotNull($information->getLogContent());
$this->assertEquals($logFile->getContent(), $information->getLogContent());
}
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace Aternos\Codex\Test\Tests\Analysis;
use Aternos\Codex\Test\Src\Analysis\TestProblem;
use Aternos\Codex\Test\Src\Analysis\TestSolution;
use PHPUnit\Framework\TestCase;
class ProblemTest extends TestCase
{
public function testSetGetSolutions(): void
{
$problem = new TestProblem();
$solution = new TestSolution();
$this->assertSame($problem, $problem->setSolutions([$solution]));
$this->assertEquals([$solution], $problem->getSolutions());
}
public function testAddSolutions(): void
{
$problem = new TestProblem();
$solution = new TestSolution();
$this->assertSame($problem, $problem->addSolution($solution));
$this->assertEquals([$solution], $problem->getSolutions());
}
public function testKey(): void
{
$problem = new TestProblem();
$solution = new TestSolution();
$problem->addSolution($solution);
/** @noinspection PhpStatementHasEmptyBodyInspection */
foreach ($problem as $ignored) {
// do nothing
}
$this->assertEquals(1, $problem->key());
}
public function testCount(): void
{
$problem = new TestProblem();
$solution1 = new TestSolution();
$solution2 = new TestSolution();
$this->assertEquals(0, $problem->count());
$problem->addSolution($solution1);
$this->assertEquals(1, $problem->count());
$problem->addSolution($solution2);
$this->assertEquals(2, $problem->count());
}
public function testOffsetExists(): void
{
$problem = new TestProblem();
$solution = new TestSolution();
$this->assertArrayNotHasKey(0, $problem);
$this->assertEquals(0, $problem->count());
$problem->addSolution($solution);
$this->assertArrayHasKey(0, $problem);
$this->assertEquals($solution, $problem[0]);
}
public function testOffsetGet(): void
{
$problem = new TestProblem();
$solution = new TestSolution();
$problem->addSolution($solution);
// Exists
$this->assertEquals($solution, $problem[0]);
// Does not exist -> "undefined array key" error
$this->assertArrayNotHasKey(1, $problem);
}
public function testOffsetSet(): void
{
$problem = new TestProblem();
$solution1 = new TestSolution();
$this->assertArrayNotHasKey(0, $problem);
$this->assertEquals(0, $problem->count());
$problem->addSolution($solution1);
$this->assertArrayHasKey(0, $problem);
$this->assertEquals($solution1, $problem[0]);
// Overwrite $solution1 on $problem[0] using the offsetSet
$TestSolution2 = new TestSolution();
$problem[0] = $TestSolution2;
$this->assertEquals($TestSolution2, $problem[0]);
}
public function testOffsetUnset(): void
{
$problem = new TestProblem();
$solution = new TestSolution();
$this->assertArrayNotHasKey(0, $problem);
$this->assertEquals(0, $problem->count());
$problem->addSolution($solution);
$this->assertArrayHasKey(0, $problem);
$this->assertEquals($solution, $problem[0]);
// Unset $solution on $problem[0] using the offsetUnset
unset($problem[0]);
$this->assertArrayNotHasKey(0, $problem);
$this->assertArrayNotHasKey(1, $problem);
}
}