Finished Logger tests

This commit is contained in:
Florian Bouillon 2019-04-17 01:29:57 +02:00
parent f7001060ea
commit 56b99ffff1
2 changed files with 34 additions and 2 deletions

View File

@ -59,7 +59,7 @@ class Logger extends AbstractLogger
file_put_contents($this->file, $this->fillMessage($this->start . $this->exception, $context), FILE_APPEND);
}
if ($message === null && !isset($context["exception"])) {
throw new InvalidArgumentException("no exception nor message was found");
throw new InvalidArgumentException("Message and Exception not set");
}
}
}

View File

@ -3,6 +3,7 @@
use PHPUnit\Framework\TestCase;
use AdminPanel\Cache\FileCache;
use AdminPanel\Logger;
use Psr\Log\InvalidArgumentException;
final class LoggerTest extends TestCase
{
@ -29,7 +30,6 @@ final class LoggerTest extends TestCase
unlink($file);
}
$logger = new Logger($file);
$this->assertFileExists($file);
$exception = new Exception("hello phpunit");
$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"
);
}
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();
}
}