Initial import from aternosorg/codex-minecraft
This commit is contained in:
138
test/tests/Log/EntryTest.php
Normal file
138
test/tests/Log/EntryTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
17
test/tests/Log/File/PathLogFileTest.php
Normal file
17
test/tests/Log/File/PathLogFileTest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Tests\Log\File;
|
||||
|
||||
use Aternos\Codex\Log\File\PathLogFile;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PathLogFileTest extends TestCase
|
||||
{
|
||||
public function testGetContent(): void
|
||||
{
|
||||
$path = __DIR__ . "/../../../data/simple.log";
|
||||
$logFile = new PathLogFile($path);
|
||||
|
||||
$this->assertStringEqualsFile($path, $logFile->getContent());
|
||||
}
|
||||
}
|
||||
18
test/tests/Log/File/StreamLogFileTest.php
Normal file
18
test/tests/Log/File/StreamLogFileTest.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Tests\Log\File;
|
||||
|
||||
use Aternos\Codex\Log\File\StreamLogFile;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class StreamLogFileTest extends TestCase
|
||||
{
|
||||
public function testGetContent(): void
|
||||
{
|
||||
$path = __DIR__ . "/../../../data/simple.log";
|
||||
$streamResource = fopen($path, 'r');
|
||||
|
||||
$logFile = new StreamLogFile($streamResource);
|
||||
$this->assertStringEqualsFile($path, $logFile->getContent());
|
||||
}
|
||||
}
|
||||
17
test/tests/Log/File/StringLogFileTest.php
Normal file
17
test/tests/Log/File/StringLogFileTest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Tests\Log\File;
|
||||
|
||||
use Aternos\Codex\Log\File\StringLogFile;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class StringLogFileTest extends TestCase
|
||||
{
|
||||
public function testGetContent(): void
|
||||
{
|
||||
$content = uniqid();
|
||||
$logFile = new StringLogFile($content);
|
||||
|
||||
$this->assertEquals($content, $logFile->getContent());
|
||||
}
|
||||
}
|
||||
33
test/tests/Log/LineTest.php
Normal file
33
test/tests/Log/LineTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Tests\Log;
|
||||
|
||||
use Aternos\Codex\Log\Line;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LineTest extends TestCase
|
||||
{
|
||||
public function testSetGetText(): void
|
||||
{
|
||||
$text = uniqid();
|
||||
$line = new Line(1, "");
|
||||
$this->assertSame($line, $line->setText($text));
|
||||
$this->assertEquals($text, $line->getText());
|
||||
}
|
||||
|
||||
public function testSetGetNumber(): void
|
||||
{
|
||||
$number = rand(0, 100);
|
||||
$line = new Line(999, "");
|
||||
$this->assertSame($line, $line->setNumber($number));
|
||||
$this->assertEquals($number, $line->getNumber());
|
||||
}
|
||||
|
||||
public function test__toString(): void
|
||||
{
|
||||
$text = uniqid();
|
||||
$line = new Line(1, $text);
|
||||
$this->assertSame($line, $line->setText($text));
|
||||
$this->assertEquals($text, (string)$line);
|
||||
}
|
||||
}
|
||||
103
test/tests/Log/LogTest.php
Normal file
103
test/tests/Log/LogTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Aternos\Codex\Test\Tests\Log;
|
||||
|
||||
use Aternos\Codex\Log\Entry;
|
||||
use Aternos\Codex\Log\Log;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LogTest extends TestCase
|
||||
{
|
||||
public function testAddEntry(): void
|
||||
{
|
||||
$log = new Log();
|
||||
$entry = new Entry();
|
||||
$this->assertSame($log, $log->addEntry($entry));
|
||||
$this->assertEquals([$entry], $log->getEntries());
|
||||
}
|
||||
|
||||
public function testSetGetEntries(): void
|
||||
{
|
||||
$log = new Log();
|
||||
$entry = new Entry();
|
||||
$this->assertSame($log, $log->setEntries([$entry]));
|
||||
$this->assertEquals([$entry], $log->getEntries());
|
||||
}
|
||||
|
||||
|
||||
public function testKey(): void
|
||||
{
|
||||
$log = new Log();
|
||||
$entry = new Entry();
|
||||
|
||||
$log->addEntry($entry);
|
||||
/** @noinspection PhpStatementHasEmptyBodyInspection */
|
||||
foreach ($log as $ignored) {
|
||||
// do nothing
|
||||
}
|
||||
$this->assertEquals(1, $log->key());
|
||||
}
|
||||
|
||||
|
||||
public function testCount(): void
|
||||
{
|
||||
$log = new Log();
|
||||
$entry1 = new Entry();
|
||||
$entry2 = new Entry();
|
||||
|
||||
$this->assertEquals(0, $log->count());
|
||||
$log->addEntry($entry1);
|
||||
$this->assertEquals(1, $log->count());
|
||||
$log->addEntry($entry2);
|
||||
$this->assertEquals(2, $log->count());
|
||||
}
|
||||
|
||||
public function testOffsetExists(): void
|
||||
{
|
||||
$log = new Log();
|
||||
$entry = new Entry();
|
||||
|
||||
$this->assertArrayNotHasKey(0, $log);
|
||||
$this->assertEquals(0, $log->count());
|
||||
$log->addEntry($entry);
|
||||
$this->assertArrayHasKey(0, $log);
|
||||
$this->assertEquals($entry, $log[0]);
|
||||
}
|
||||
|
||||
public function testOffsetGet(): void
|
||||
{
|
||||
$log = new Log();
|
||||
$entry = new Entry();
|
||||
$log->addEntry($entry);
|
||||
|
||||
// Exists
|
||||
$this->assertEquals($entry, $log[0]);
|
||||
|
||||
// Does not exist -> "undefined array key" error
|
||||
$this->assertArrayNotHasKey(1, $log);
|
||||
}
|
||||
|
||||
public function testOffsetSet(): void
|
||||
{
|
||||
$log = new Log();
|
||||
$entry1 = new Entry();
|
||||
$log->addEntry($entry1);
|
||||
|
||||
// Overwrite $entry1 on $log[0] using the offsetSet
|
||||
$entry2 = new Entry();
|
||||
$log[0] = $entry2;
|
||||
$this->assertEquals($entry2, $log[0]);
|
||||
}
|
||||
|
||||
public function testOffsetUnset(): void
|
||||
{
|
||||
$log = new Log();
|
||||
$entry = new Entry();
|
||||
$log->addEntry($entry);
|
||||
|
||||
// Unset $entry on $log[0] using the offsetUnset
|
||||
unset($log[0]);
|
||||
$this->assertArrayNotHasKey(0, $log);
|
||||
$this->assertArrayNotHasKey(1, $log);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user