Files
ik-codex/test/tests/Log/EntryTest.php
indifferentketchup 7c7fe5ca80
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
Initial import from aternosorg/codex-minecraft
2026-04-30 09:56:57 -05:00

139 lines
3.7 KiB
PHP

<?php
namespace Aternos\Codex\Test\Tests\Log;
use Aternos\Codex\Log\Entry;
use Aternos\Codex\Log\Level;
use Aternos\Codex\Log\Line;
use PHPUnit\Framework\TestCase;
class EntryTest extends TestCase
{
public function testAddLine(): void
{
$entry = new Entry();
$line = new Line(1, uniqid());
$this->assertSame($entry, $entry->addLine($line));
$this->assertEquals([$line], $entry->getLines());
}
public function testSetGetLines(): void
{
$entry = new Entry();
$line = new Line(1, uniqid());
$this->assertSame($entry, $entry->setLines([$line]));
$this->assertEquals([$line], $entry->getLines());
}
public function testSetGetLevel(): void
{
$entry = new Entry();
$level = Level::CRITICAL;
$this->assertSame($entry, $entry->setLevel($level));
$this->assertEquals($level, $entry->getLevel());
}
public function testSetGetTime(): void
{
$entry = new Entry();
$time = time();
$this->assertSame($entry, $entry->setTime($time));
$this->assertEquals($time, $entry->getTime());
}
public function testSetGetPrefix(): void
{
$entry = new Entry();
$prefix = uniqid();
$this->assertSame($entry, $entry->setPrefix($prefix));
$this->assertEquals($prefix, $entry->getPrefix());
}
public function testKey(): void
{
$entry = new Entry();
$line = new Line(1, uniqid());
$entry->addLine($line);
/** @noinspection PhpStatementHasEmptyBodyInspection */
foreach ($entry as $ignored) {
// do nothing
}
$this->assertEquals(1, $entry->key());
}
public function testCount(): void
{
$entry = new Entry();
$line1 = new Line(1, uniqid());
$line2 = new Line(2, uniqid());
$this->assertEquals(0, $entry->count());
$entry->addLine($line1);
$this->assertEquals(1, $entry->count());
$entry->addLine($line2);
$this->assertEquals(2, $entry->count());
}
public function testOffsetExists(): void
{
$entry = new Entry();
$line = new Line(1, uniqid());
$this->assertArrayNotHasKey(0, $entry);
$this->assertEquals(0, $entry->count());
$entry->addLine($line);
$this->assertArrayHasKey(0, $entry);
$this->assertEquals($line, $entry[0]);
}
public function testOffsetGet(): void
{
$entry = new Entry();
$line = new Line(1, uniqid());
$entry->addLine($line);
// Exists
$this->assertEquals($line, $entry[0]);
// Does not exist -> "undefined array key" error
$this->assertArrayNotHasKey(1, $entry);
}
public function testOffsetSet(): void
{
$entry = new Entry();
$line1 = new Line(1, uniqid());
$this->assertArrayNotHasKey(0, $entry);
$this->assertEquals(0, $entry->count());
$entry->addLine($line1);
$this->assertArrayHasKey(0, $entry);
$this->assertEquals($line1, $entry[0]);
// Overwrite $line1 on $entry[0] using the offsetSet
$line2 = new Line(2, uniqid());
$entry[0] = $line2;
$this->assertEquals($line2, $entry[0]);
}
public function testOffsetUnset(): void
{
$entry = new Entry();
$line = new Line(1, uniqid());
$this->assertArrayNotHasKey(0, $entry);
$this->assertEquals(0, $entry->count());
$entry->addLine($line);
$this->assertArrayHasKey(0, $entry);
$this->assertEquals($line, $entry[0]);
// Unset $line1 on $entry[0] using the offsetUnset
unset($entry[0]);
$this->assertArrayNotHasKey(0, $entry);
$this->assertArrayNotHasKey(1, $entry);
}
}