aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Log
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Log')
-rw-r--r--tests/lib/Log/FileTest.php11
-rw-r--r--tests/lib/Log/LogFactoryTest.php34
-rw-r--r--tests/lib/Log/PsrLoggerAdapterTest.php16
3 files changed, 33 insertions, 28 deletions
diff --git a/tests/lib/Log/FileTest.php b/tests/lib/Log/FileTest.php
index b483da969f4..3f030665fb4 100644
--- a/tests/lib/Log/FileTest.php
+++ b/tests/lib/Log/FileTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
*
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
@@ -8,8 +9,10 @@
namespace Test\Log;
use OC\Log\File;
+use OC\SystemConfig;
use OCP\IConfig;
use OCP\ILogger;
+use OCP\Server;
use Test\TestCase;
/**
@@ -24,7 +27,7 @@ class FileTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $config = \OC::$server->getSystemConfig();
+ $config = Server::get(SystemConfig::class);
$this->restore_logfile = $config->getValue('logfile');
$this->restore_logdateformat = $config->getValue('logdateformat');
@@ -32,7 +35,7 @@ class FileTest extends TestCase {
$this->logFile = new File($config->getValue('datadirectory') . '/logtest.log', '', $config);
}
protected function tearDown(): void {
- $config = \OC::$server->getSystemConfig();
+ $config = Server::get(SystemConfig::class);
if (isset($this->restore_logfile)) {
$config->getValue('logfile', $this->restore_logfile);
} else {
@@ -48,7 +51,7 @@ class FileTest extends TestCase {
}
public function testLogging(): void {
- $config = \OC::$server->get(IConfig::class);
+ $config = Server::get(IConfig::class);
# delete old logfile
unlink($config->getSystemValue('logfile'));
@@ -69,7 +72,7 @@ class FileTest extends TestCase {
}
public function testMicrosecondsLogTimestamp(): void {
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
# delete old logfile
unlink($config->getSystemValue('logfile'));
diff --git a/tests/lib/Log/LogFactoryTest.php b/tests/lib/Log/LogFactoryTest.php
index 6219fd438f7..b1adbd0e823 100644
--- a/tests/lib/Log/LogFactoryTest.php
+++ b/tests/lib/Log/LogFactoryTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -12,6 +13,7 @@ use OC\Log\LogFactory;
use OC\Log\Syslog;
use OC\Log\Systemdlog;
use OC\SystemConfig;
+use OCP\AppFramework\QueryException;
use OCP\IServerContainer;
use Test\TestCase;
@@ -39,7 +41,7 @@ class LogFactoryTest extends TestCase {
$this->factory = new LogFactory($this->c, $this->systemConfig);
}
- public function fileTypeProvider(): array {
+ public static function fileTypeProvider(): array {
return [
[
'file'
@@ -58,23 +60,26 @@ class LogFactoryTest extends TestCase {
/**
* @param string $type
- * @dataProvider fileTypeProvider
- * @throws \OCP\AppFramework\QueryException
+ * @throws QueryException
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('fileTypeProvider')]
public function testFile(string $type): void {
$datadir = \OC::$SERVERROOT . '/data';
$defaultLog = $datadir . '/nextcloud.log';
$this->systemConfig->expects($this->exactly(3))
->method('getValue')
- ->withConsecutive(['datadirectory', $datadir], ['logfile', $defaultLog], ['logfilemode', 0640])
- ->willReturnOnConsecutiveCalls($datadir, $defaultLog, 0640);
+ ->willReturnMap([
+ ['datadirectory', $datadir, $datadir],
+ ['logfile', $defaultLog, $defaultLog],
+ ['logfilemode', 0640, 0640],
+ ]);
$log = $this->factory->get($type);
$this->assertInstanceOf(File::class, $log);
}
- public function logFilePathProvider():array {
+ public static function logFilePathProvider():array {
return [
[
'/dev/null',
@@ -88,17 +93,20 @@ class LogFactoryTest extends TestCase {
}
/**
- * @dataProvider logFilePathProvider
- * @throws \OCP\AppFramework\QueryException
+ * @throws QueryException
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('logFilePathProvider')]
public function testFileCustomPath($path, $expected): void {
$datadir = \OC::$SERVERROOT . '/data';
$defaultLog = $datadir . '/nextcloud.log';
$this->systemConfig->expects($this->exactly(3))
->method('getValue')
- ->withConsecutive(['datadirectory', $datadir], ['logfile', $defaultLog], ['logfilemode', 0640])
- ->willReturnOnConsecutiveCalls($datadir, $path, 0640);
+ ->willReturnMap([
+ ['datadirectory', $datadir, $datadir],
+ ['logfile', $defaultLog, $path],
+ ['logfilemode', 0640, 0640],
+ ]);
$log = $this->factory->get('file');
$this->assertInstanceOf(File::class, $log);
@@ -106,7 +114,7 @@ class LogFactoryTest extends TestCase {
}
/**
- * @throws \OCP\AppFramework\QueryException
+ * @throws QueryException
*/
public function testErrorLog(): void {
$log = $this->factory->get('errorlog');
@@ -114,7 +122,7 @@ class LogFactoryTest extends TestCase {
}
/**
- * @throws \OCP\AppFramework\QueryException
+ * @throws QueryException
*/
public function testSystemLog(): void {
$this->c->expects($this->once())
@@ -127,7 +135,7 @@ class LogFactoryTest extends TestCase {
}
/**
- * @throws \OCP\AppFramework\QueryException
+ * @throws QueryException
*/
public function testSystemdLog(): void {
$this->c->expects($this->once())
diff --git a/tests/lib/Log/PsrLoggerAdapterTest.php b/tests/lib/Log/PsrLoggerAdapterTest.php
index cc9ddea378a..c11af7a12c2 100644
--- a/tests/lib/Log/PsrLoggerAdapterTest.php
+++ b/tests/lib/Log/PsrLoggerAdapterTest.php
@@ -28,9 +28,7 @@ class PsrLoggerAdapterTest extends TestCase {
$this->loggerAdapter = new PsrLoggerAdapter($this->logger);
}
- /**
- * @dataProvider dataPsrLoggingLevels
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataPsrLoggingLevels')]
public function testLoggingWithPsrLogLevels(string $level, int $expectedLevel): void {
$this->logger->expects(self::once())
->method('log')
@@ -38,14 +36,12 @@ class PsrLoggerAdapterTest extends TestCase {
$this->loggerAdapter->log($level, 'test message', ['app' => 'test']);
}
- /**
- * @dataProvider dataPsrLoggingLevels
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataPsrLoggingLevels')]
public function testLogLevelToInt(string $level, int $expectedLevel): void {
$this->assertEquals($expectedLevel, PsrLoggerAdapter::logLevelToInt($level));
}
- public function dataPsrLoggingLevels(): array {
+ public static function dataPsrLoggingLevels(): array {
return [
[LogLevel::ALERT, ILogger::ERROR],
[LogLevel::CRITICAL, ILogger::ERROR],
@@ -58,9 +54,7 @@ class PsrLoggerAdapterTest extends TestCase {
];
}
- /**
- * @dataProvider dataInvalidLoggingLevel
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataInvalidLoggingLevel')]
public function testInvalidLoggingLevel($level): void {
$this->logger->expects(self::never())
->method('log');
@@ -69,7 +63,7 @@ class PsrLoggerAdapterTest extends TestCase {
$this->loggerAdapter->log($level, 'valid message');
}
- public function dataInvalidLoggingLevel(): array {
+ public static function dataInvalidLoggingLevel(): array {
return [
// invalid string
['this is not a level'],