Merge branch 'develop' into eventdispatcher-part3
This commit is contained in:
commit
ec16994738
21 changed files with 572 additions and 132 deletions
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Test\Unit\Core\Logger\Factory;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Logger\Capability\LogChannel;
|
||||
use Friendica\Core\Logger\Factory\DelegatingLoggerFactory;
|
||||
use Friendica\Core\Logger\Factory\LoggerFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
class DelegatingLoggerFactoryTest extends TestCase
|
||||
{
|
||||
public function testCreateLoggerReturnsPsrLogger(): void
|
||||
{
|
||||
$config = $this->createStub(IManageConfigValues::class);
|
||||
$config->method('get')->willReturnMap([
|
||||
['system', 'logger_config', null, 'test'],
|
||||
]);
|
||||
|
||||
$factory = new DelegatingLoggerFactory($config);
|
||||
|
||||
$factory->registerFactory('test', $this->createStub(LoggerFactory::class));
|
||||
|
||||
$this->assertInstanceOf(
|
||||
LoggerInterface::class,
|
||||
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateLoggerWithoutRegisteredFactoryReturnsNullLogger(): void
|
||||
{
|
||||
$config = $this->createStub(IManageConfigValues::class);
|
||||
$config->method('get')->willReturnMap([
|
||||
['system', 'logger_config', null, 'not-existing-factory'],
|
||||
]);
|
||||
|
||||
$factory = new DelegatingLoggerFactory($config);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
NullLogger::class,
|
||||
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateLoggerWithExceptionThrowingFactoryReturnsNullLogger(): void
|
||||
{
|
||||
$config = $this->createStub(IManageConfigValues::class);
|
||||
$config->method('get')->willReturnMap([
|
||||
['system', 'logger_config', null, 'test'],
|
||||
]);
|
||||
|
||||
$factory = new DelegatingLoggerFactory($config);
|
||||
|
||||
$brokenFactory = $this->createStub(LoggerFactory::class);
|
||||
$brokenFactory->method('createLogger')->willThrowException(new Exception());
|
||||
|
||||
$factory->registerFactory('test', $brokenFactory);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
NullLogger::class,
|
||||
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Test\Unit\Core\Logger\Factory;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Hooks\Capability\ICanCreateInstances;
|
||||
use Friendica\Core\Logger\Capability\LogChannel;
|
||||
use Friendica\Core\Logger\Factory\LegacyLoggerFactory;
|
||||
use Friendica\Util\Profiler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
class LegacyLoggerFactoryTest extends TestCase
|
||||
{
|
||||
public function testCreateLoggerReturnsPsrLogger(): void
|
||||
{
|
||||
$factory = new LegacyLoggerFactory(
|
||||
$this->createStub(ICanCreateInstances::class),
|
||||
$this->createStub(IManageConfigValues::class),
|
||||
$this->createStub(Profiler::class),
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
LoggerInterface::class,
|
||||
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
|
||||
);
|
||||
}
|
||||
}
|
81
tests/Unit/Core/Logger/Factory/StreamLoggerFactoryTest.php
Normal file
81
tests/Unit/Core/Logger/Factory/StreamLoggerFactoryTest.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Test\Unit\Core\Logger\Factory;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Logger\Capability\IHaveCallIntrospections;
|
||||
use Friendica\Core\Logger\Capability\LogChannel;
|
||||
use Friendica\Core\Logger\Exception\LoggerArgumentException;
|
||||
use Friendica\Core\Logger\Exception\LogLevelException;
|
||||
use Friendica\Core\Logger\Factory\StreamLoggerFactory;
|
||||
use Friendica\Core\Logger\Util\FileSystemUtil;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
class StreamLoggerFactoryTest extends TestCase
|
||||
{
|
||||
public function testCreateLoggerReturnsPsrLogger(): void
|
||||
{
|
||||
$config = $this->createStub(IManageConfigValues::class);
|
||||
$config->method('get')->willReturnMap([
|
||||
['system', 'logfile', null, dirname(__DIR__, 4) . '/datasets/log/empty.friendica.log.txt'],
|
||||
]);
|
||||
|
||||
$factory = new StreamLoggerFactory(
|
||||
$config,
|
||||
$this->createStub(IHaveCallIntrospections::class),
|
||||
$this->createStub(FileSystemUtil::class),
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
LoggerInterface::class,
|
||||
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateLoggerWithInvalidLogfileThrowsException(): void
|
||||
{
|
||||
$config = $this->createStub(IManageConfigValues::class);
|
||||
$config->method('get')->willReturnMap([
|
||||
['system', 'logfile', null, dirname(__DIR__, 1) . '/not-existing-logfile.txt'],
|
||||
]);
|
||||
|
||||
$factory = new StreamLoggerFactory(
|
||||
$config,
|
||||
$this->createStub(IHaveCallIntrospections::class),
|
||||
$this->createStub(FileSystemUtil::class),
|
||||
);
|
||||
|
||||
$this->expectException(LoggerArgumentException::class);
|
||||
$this->expectExceptionMessage('tests/Unit/Core/Logger/not-existing-logfile.txt" is not a valid logfile.');
|
||||
|
||||
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT);
|
||||
}
|
||||
|
||||
public function testCreateLoggerWithInvalidLoglevelThrowsException(): void
|
||||
{
|
||||
$config = $this->createStub(IManageConfigValues::class);
|
||||
$config->method('get')->willReturnMap([
|
||||
['system', 'logfile', null, dirname(__DIR__, 4) . '/datasets/log/empty.friendica.log.txt'],
|
||||
]);
|
||||
|
||||
$factory = new StreamLoggerFactory(
|
||||
$config,
|
||||
$this->createStub(IHaveCallIntrospections::class),
|
||||
$this->createStub(FileSystemUtil::class),
|
||||
);
|
||||
|
||||
$this->expectException(LogLevelException::class);
|
||||
$this->expectExceptionMessage('The log level "unsupported-loglevel" is not supported by "Friendica\Core\Logger\Type\StreamLogger".');
|
||||
|
||||
$factory->createLogger('unsupported-loglevel', LogChannel::DEFAULT);
|
||||
}
|
||||
}
|
61
tests/Unit/Core/Logger/Factory/SyslogLoggerFactoryTest.php
Normal file
61
tests/Unit/Core/Logger/Factory/SyslogLoggerFactoryTest.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Test\Unit\Core\Logger\Factory;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Logger\Capability\IHaveCallIntrospections;
|
||||
use Friendica\Core\Logger\Capability\LogChannel;
|
||||
use Friendica\Core\Logger\Exception\LogLevelException;
|
||||
use Friendica\Core\Logger\Factory\SyslogLoggerFactory;
|
||||
use Friendica\Core\Logger\Type\SyslogLogger;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
class SyslogLoggerFactoryTest extends TestCase
|
||||
{
|
||||
public function testCreateLoggerReturnsPsrLogger(): void
|
||||
{
|
||||
$config = $this->createStub(IManageConfigValues::class);
|
||||
$config->method('get')->willReturnMap([
|
||||
['system', 'syslog_flags', null, SyslogLogger::DEFAULT_FLAGS],
|
||||
['system', 'syslog_facility', null, SyslogLogger::DEFAULT_FACILITY],
|
||||
]);
|
||||
|
||||
$factory = new SyslogLoggerFactory(
|
||||
$config,
|
||||
$this->createStub(IHaveCallIntrospections::class),
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
LoggerInterface::class,
|
||||
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateLoggerWithInvalidLoglevelThrowsException(): void
|
||||
{
|
||||
$config = $this->createStub(IManageConfigValues::class);
|
||||
$config->method('get')->willReturnMap([
|
||||
['system', 'syslog_flags', null, SyslogLogger::DEFAULT_FLAGS],
|
||||
['system', 'syslog_facility', null, SyslogLogger::DEFAULT_FACILITY],
|
||||
]);
|
||||
|
||||
$factory = new SyslogLoggerFactory(
|
||||
$config,
|
||||
$this->createStub(IHaveCallIntrospections::class),
|
||||
);
|
||||
|
||||
$this->expectException(LogLevelException::class);
|
||||
$this->expectExceptionMessage('The log level "unsupported-loglevel" is not supported by "Friendica\Core\Logger\Type\SyslogLogger".');
|
||||
|
||||
$factory->createLogger('unsupported-loglevel', LogChannel::DEFAULT);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue