adjust tests to new exception log format
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
b9583c6dce
commit
15815c034f
2 changed files with 31 additions and 14 deletions
|
@ -24,6 +24,7 @@
|
|||
|
||||
namespace OCA\DAV\Tests\unit\Connector\Sabre;
|
||||
|
||||
use OC\SystemConfig;
|
||||
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
|
||||
use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin as PluginToTest;
|
||||
use OC\Log;
|
||||
|
@ -37,13 +38,9 @@ class TestLogger extends Log {
|
|||
public $message;
|
||||
public $level;
|
||||
|
||||
public function __construct($logger = null) {
|
||||
//disable original constructor
|
||||
}
|
||||
|
||||
public function log(int $level, string $message, array $context = array()) {
|
||||
public function writeLog(string $app, $entry, int $level) {
|
||||
$this->level = $level;
|
||||
$this->message = $message;
|
||||
$this->message = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,8 +56,20 @@ class ExceptionLoggerPluginTest extends TestCase {
|
|||
private $logger;
|
||||
|
||||
private function init() {
|
||||
$config = $this->createMock(SystemConfig::class);
|
||||
$config->expects($this->any())
|
||||
->method('getValue')
|
||||
->willReturnCallback(function($key, $default) {
|
||||
switch ($key) {
|
||||
case 'loglevel':
|
||||
return 0;
|
||||
default:
|
||||
return $default;
|
||||
}
|
||||
});
|
||||
|
||||
$this->server = new Server();
|
||||
$this->logger = new TestLogger();
|
||||
$this->logger = new TestLogger(Log\File::class, $config);
|
||||
$this->plugin = new PluginToTest('unit-test', $this->logger);
|
||||
$this->plugin->initialize($this->server);
|
||||
}
|
||||
|
@ -73,7 +82,8 @@ class ExceptionLoggerPluginTest extends TestCase {
|
|||
$this->plugin->logException($exception);
|
||||
|
||||
$this->assertEquals($expectedLogLevel, $this->logger->level);
|
||||
$this->assertStringStartsWith('Exception: {"Exception":' . json_encode(get_class($exception)) . ',"Message":"' . $expectedMessage . '",', $this->logger->message);
|
||||
$this->assertEquals(get_class($exception), $this->logger->message['Exception']);
|
||||
$this->assertEquals($expectedMessage, $this->logger->message['Message']);
|
||||
}
|
||||
|
||||
public function providesExceptions() {
|
||||
|
|
|
@ -265,7 +265,7 @@ class Log implements ILogger {
|
|||
$message = strtr($message, $replace);
|
||||
|
||||
if ($level >= $minLevel) {
|
||||
call_user_func([$this->logger, 'write'], $app, $message, $level);
|
||||
$this->writeLog($app, $message, $level);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,12 +383,10 @@ class Log implements ILogger {
|
|||
array_walk($context, [$this->normalizer, 'format']);
|
||||
|
||||
if ($level >= $minLevel) {
|
||||
if ($this->logger === File::class) {
|
||||
call_user_func([$this->logger, 'write'], $app, $data, $level);
|
||||
} else {
|
||||
$entry = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR);
|
||||
call_user_func([$this->logger, 'write'], $app, $entry, $level);
|
||||
if ($this->logger !== File::class) {
|
||||
$data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR);
|
||||
}
|
||||
$this->writeLog($app, $data, $level);
|
||||
}
|
||||
|
||||
$context['level'] = $level;
|
||||
|
@ -397,6 +395,15 @@ class Log implements ILogger {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $app
|
||||
* @param string|array $entry
|
||||
* @param int $level
|
||||
*/
|
||||
protected function writeLog(string $app, $entry, int $level) {
|
||||
call_user_func([$this->logger, 'write'], $app, $entry, $level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $logType
|
||||
* @return string
|
||||
|
|
Loading…
Reference in a new issue