12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- declare(strict_types=1);
- namespace Test\Log;
- use OC\Log;
- use OC\Log\PsrLoggerAdapter;
- use OCP\ILogger;
- use PHPUnit\Framework\MockObject\MockObject;
- use Psr\Log\InvalidArgumentException;
- use Psr\Log\LogLevel;
- use Test\TestCase;
- class PsrLoggerAdapterTest extends TestCase {
- protected Log&MockObject $logger;
- protected PsrLoggerAdapter $loggerAdapter;
- protected function setUp(): void {
- parent::setUp();
- $this->logger = $this->createMock(Log::class);
- $this->loggerAdapter = new PsrLoggerAdapter($this->logger);
- }
-
- public function testLoggingWithPsrLogLevels(string $level, int $expectedLevel): void {
- $this->logger->expects(self::once())
- ->method('log')
- ->with($expectedLevel, 'test message', ['app' => 'test']);
- $this->loggerAdapter->log($level, 'test message', ['app' => 'test']);
- }
-
- public function testLogLevelToInt(string $level, int $expectedLevel): void {
- $this->assertEquals($expectedLevel, PsrLoggerAdapter::logLevelToInt($level));
- }
- public function dataPsrLoggingLevels(): array {
- return [
- [LogLevel::ALERT, ILogger::ERROR],
- [LogLevel::CRITICAL, ILogger::ERROR],
- [LogLevel::DEBUG, ILogger::DEBUG],
- [LogLevel::EMERGENCY, ILogger::FATAL],
- [LogLevel::ERROR, ILogger::ERROR],
- [LogLevel::INFO, ILogger::INFO],
- [LogLevel::NOTICE, ILogger::INFO],
- [LogLevel::WARNING, ILogger::WARN],
- ];
- }
-
- public function testInvalidLoggingLevel($level): void {
- $this->logger->expects(self::never())
- ->method('log');
- $this->expectException(InvalidArgumentException::class);
- $this->loggerAdapter->log($level, 'valid message');
- }
- public function dataInvalidLoggingLevel(): array {
- return [
-
- ['this is not a level'],
-
- [ILogger::DEBUG - 1],
- [ILogger::FATAL + 1],
-
- [1.2345],
-
- [true],
- [false],
-
- [null],
- ];
- }
- }
|