Files
ik-codex/test/tests/Log/EntryTest.php
indifferentketchup 66a2fcc5f3 Rename namespace Aternos\Codex to IndifferentKetchup\Codex
Bulk substitution across all PHP files in src/ and test/. Covers
namespace declarations, use statements, fully-qualified class
references, and @package PHPDoc tags. No logic changes.
2026-04-30 15:13:52 +00:00

139 lines
3.8 KiB
PHP

<?php
namespace IndifferentKetchup\Codex\Test\Tests\Log;
use IndifferentKetchup\Codex\Log\Entry;
use IndifferentKetchup\Codex\Log\Level;
use IndifferentKetchup\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);
}
}