From 2df76617c17d3a090f582e5bcb214312f7f601bf Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 10 Jan 2025 15:21:56 +0000 Subject: [PATCH] Rename LoggerFactory into LoggerManager --- .../LoggerFactory.php => LoggerManager.php} | 11 ++-- .../Core/Logger/Factory/LoggerFactoryTest.php | 59 ------------------- tests/Unit/Core/Logger/LoggerManagerTest.php | 59 +++++++++++++++++++ 3 files changed, 66 insertions(+), 63 deletions(-) rename src/Core/Logger/{Factory/LoggerFactory.php => LoggerManager.php} (89%) delete mode 100644 tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php create mode 100644 tests/Unit/Core/Logger/LoggerManagerTest.php diff --git a/src/Core/Logger/Factory/LoggerFactory.php b/src/Core/Logger/LoggerManager.php similarity index 89% rename from src/Core/Logger/Factory/LoggerFactory.php rename to src/Core/Logger/LoggerManager.php index 5742fdd5b5..4524e80f59 100644 --- a/src/Core/Logger/Factory/LoggerFactory.php +++ b/src/Core/Logger/LoggerManager.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Friendica\Core\Logger\Factory; +namespace Friendica\Core\Logger; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Logger\Capability\LogChannel; @@ -18,9 +18,9 @@ use Psr\Log\LogLevel; use Psr\Log\NullLogger; /** - * The logger factory for the core logging instances + * Manager for the core logging instances */ -final class LoggerFactory +final class LoggerManager { private IManageConfigValues $config; @@ -44,7 +44,10 @@ final class LoggerFactory $this->profiling = (bool) $config->get('system', 'profiling') ?? false; } - public function create(): LoggerInterface + /** + * (Creates and) Returns the logger instance + */ + public function getLogger(): LoggerInterface { if (! isset($this->logger)) { $this->logger = $this->createProfiledLogger(); diff --git a/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php b/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php deleted file mode 100644 index e97f79f82f..0000000000 --- a/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php +++ /dev/null @@ -1,59 +0,0 @@ -createStub(IManageConfigValues::class)); - - $this->assertInstanceOf(LoggerInterface::class, $factory->create()); - } - - public function testCreateReturnsSameObject(): void - { - $factory = new LoggerFactory($this->createStub(IManageConfigValues::class)); - - $this->assertSame($factory->create(), $factory->create()); - } - - public function testCreateWithDebugDisabledReturnsNullLogger(): void - { - $config = $this->createStub(IManageConfigValues::class); - $config->method('get')->willReturnMap([ - ['system', 'debugging', null, false], - ]); - - $factory = new LoggerFactory($config); - - $this->assertInstanceOf(NullLogger::class, $factory->create()); - } - - public function testCreateWithProfilerEnabledReturnsProfilerLogger(): void - { - $config = $this->createStub(IManageConfigValues::class); - $config->method('get')->willReturnMap([ - ['system', 'debugging', null, false], - ['system', 'profiling', null, true], - ]); - - $factory = new LoggerFactory($config); - - $this->assertInstanceOf(ProfilerLogger::class, $factory->create()); - } -} diff --git a/tests/Unit/Core/Logger/LoggerManagerTest.php b/tests/Unit/Core/Logger/LoggerManagerTest.php new file mode 100644 index 0000000000..d85c4e0c3a --- /dev/null +++ b/tests/Unit/Core/Logger/LoggerManagerTest.php @@ -0,0 +1,59 @@ +createStub(IManageConfigValues::class)); + + $this->assertInstanceOf(LoggerInterface::class, $factory->getLogger()); + } + + public function testGetLoggerReturnsSameObject(): void + { + $factory = new LoggerManager($this->createStub(IManageConfigValues::class)); + + $this->assertSame($factory->getLogger(), $factory->getLogger()); + } + + public function testGetLoggerWithDebugDisabledReturnsNullLogger(): void + { + $config = $this->createStub(IManageConfigValues::class); + $config->method('get')->willReturnMap([ + ['system', 'debugging', null, false], + ]); + + $factory = new LoggerManager($config); + + $this->assertInstanceOf(NullLogger::class, $factory->getLogger()); + } + + public function testGetLoggerWithProfilerEnabledReturnsProfilerLogger(): void + { + $config = $this->createStub(IManageConfigValues::class); + $config->method('get')->willReturnMap([ + ['system', 'debugging', null, false], + ['system', 'profiling', null, true], + ]); + + $factory = new LoggerManager($config); + + $this->assertInstanceOf(ProfilerLogger::class, $factory->getLogger()); + } +}