mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-06-07 23:39:54 +00:00
Finished Logger tests
This commit is contained in:
parent
f7001060ea
commit
56b99ffff1
@ -59,7 +59,7 @@ class Logger extends AbstractLogger
|
|||||||
file_put_contents($this->file, $this->fillMessage($this->start . $this->exception, $context), FILE_APPEND);
|
file_put_contents($this->file, $this->fillMessage($this->start . $this->exception, $context), FILE_APPEND);
|
||||||
}
|
}
|
||||||
if ($message === null && !isset($context["exception"])) {
|
if ($message === null && !isset($context["exception"])) {
|
||||||
throw new InvalidArgumentException("no exception nor message was found");
|
throw new InvalidArgumentException("Message and Exception not set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use AdminPanel\Cache\FileCache;
|
use AdminPanel\Cache\FileCache;
|
||||||
use AdminPanel\Logger;
|
use AdminPanel\Logger;
|
||||||
|
use Psr\Log\InvalidArgumentException;
|
||||||
|
|
||||||
final class LoggerTest extends TestCase
|
final class LoggerTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -29,7 +30,6 @@ final class LoggerTest extends TestCase
|
|||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
$logger = new Logger($file);
|
$logger = new Logger($file);
|
||||||
$this->assertFileExists($file);
|
|
||||||
|
|
||||||
$exception = new Exception("hello phpunit");
|
$exception = new Exception("hello phpunit");
|
||||||
$logger->alert("test", array(
|
$logger->alert("test", array(
|
||||||
@ -40,4 +40,36 @@ final class LoggerTest extends TestCase
|
|||||||
"[Alert]: " . (new \DateTime())->format("Y-m-d H:i:s") . " test\n[Alert]: " . (new \DateTime())->format("Y-m-d H:i:s") . " 0 " . $exception->getFile() . "[Exception] 0 " . $exception->getMessage() . "\n"
|
"[Alert]: " . (new \DateTime())->format("Y-m-d H:i:s") . " test\n[Alert]: " . (new \DateTime())->format("Y-m-d H:i:s") . " 0 " . $exception->getFile() . "[Exception] 0 " . $exception->getMessage() . "\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLevelException()
|
||||||
|
{
|
||||||
|
$file = "tests/logs.log";
|
||||||
|
if (file_exists($file)) {
|
||||||
|
unlink($file);
|
||||||
|
}
|
||||||
|
$logger = new Logger($file);
|
||||||
|
try {
|
||||||
|
$logger->log('incorrect_level', "level incorrect");
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
$this->assertEquals($e->getMessage(), "Level not supported");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNothingException()
|
||||||
|
{
|
||||||
|
$file = "tests/logs.log";
|
||||||
|
if (file_exists($file)) {
|
||||||
|
unlink($file);
|
||||||
|
}
|
||||||
|
$logger = new Logger($file);
|
||||||
|
try {
|
||||||
|
$logger->log("info");
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
$this->assertEquals($e->getMessage(), "Message and Exception not set");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->fail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user