This commit is contained in:
Dennis Eichhorn 2019-11-03 23:22:07 +01:00
parent fd768a208c
commit 8389360eba

View File

@ -24,32 +24,34 @@ require_once __DIR__ . '/../Autoloader.php';
*/
class FileLoggerTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes() : void
protected function setUp(): void
{
$log = FileLogger::getInstance(__DIR__);
self::assertObjectHasAttribute('fp', $log);
self::assertObjectHasAttribute('path', $log);
if (\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log')) {
\unlink(__DIR__ . '/' . \date('Y-m-d') . '.log');
}
}
public function testDefault() : void
protected function tearDown() : void
{
if (\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log')) {
\unlink(__DIR__ . '/' . \date('Y-m-d') . '.log');
}
}
$log = FileLogger::getInstance(__DIR__);
public function testAttributes() : void
{
$log = new FileLogger(__DIR__);
self::assertObjectHasAttribute('fp', $log);
self::assertObjectHasAttribute('path', $log);
}
public function testDefault() : void
{
$log = new FileLogger(__DIR__);
self::assertEquals([], $log->countLogs());
self::assertEquals([], $log->getHighestPerpetrator());
self::assertEquals([], $log->get());
self::assertEquals([], $log->getByLine());
if (\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log')) {
\unlink(__DIR__ . '/' . \date('Y-m-d') . '.log');
}
}
public function testGetSet() : void
@ -151,13 +153,21 @@ class FileLoggerTest extends \PHPUnit\Framework\TestCase
\unlink(__DIR__ . '/test.log');
if (\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log')) {
\unlink(__DIR__ . '/' . \date('Y-m-d') . '.log');
}
\ob_clean();
}
public function testVerbose() : void
{
$log = new FileLogger(__DIR__, true);
\ob_start();
$log->info('my log message');
$ob = \ob_get_clean();
\ob_clean();
self::assertEquals('my log message' . "\n", $ob);
}
public function testLogException() : void
{
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
@ -176,15 +186,4 @@ class FileLoggerTest extends \PHPUnit\Framework\TestCase
self::assertFalse(FileLogger::startTimeLog('test'));
self::assertGreaterThan(0.0, FileLogger::endTimeLog('test'));
}
public static function tearDownAfterClass() : void
{
if (\file_exists(__DIR__ . '/test.log')) {
\unlink(__DIR__ . '/test.log');
}
if (\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log')) {
\unlink(__DIR__ . '/' . \date('Y-m-d') . '.log');
}
}
}