LoggerFactory returns same object

This commit is contained in:
Art4 2025-01-10 10:33:55 +00:00
parent 9bcb470caa
commit 4a8533aa11
2 changed files with 14 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -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());
}
}