From 4a8533aa11a86735e5d4061c8f9ea2209d737a5f Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 10 Jan 2025 10:33:55 +0000 Subject: [PATCH] LoggerFactory returns same object --- src/Core/Logger/Factory/LoggerFactory.php | 8 +++++++- tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Core/Logger/Factory/LoggerFactory.php b/src/Core/Logger/Factory/LoggerFactory.php index 77c06d4f89..c789028a08 100644 --- a/src/Core/Logger/Factory/LoggerFactory.php +++ b/src/Core/Logger/Factory/LoggerFactory.php @@ -17,8 +17,14 @@ use Psr\Log\NullLogger; */ final class LoggerFactory { + private LoggerInterface $logger; + public function create(): LoggerInterface { - return new NullLogger(); + if (! isset($this->logger)) { + $this->logger = new NullLogger(); + } + + return $this->logger; } } diff --git a/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php b/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php index 71ce0c741d..1c42ec39dd 100644 --- a/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php +++ b/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php @@ -21,4 +21,11 @@ class LoggerFactoryTest extends TestCase $this->assertInstanceOf(LoggerInterface::class, $factory->create()); } + + public function testLoggerFactoryCreateReturnsSameObject(): void + { + $factory = new LoggerFactory(); + + $this->assertSame($factory->create(), $factory->create()); + } }