]> git.mxchange.org Git - friendica.git/commitdiff
Clean private static properties of LoggerManager via tearDown method
authorArt4 <art4@wlabs.de>
Mon, 13 Jan 2025 16:52:05 +0000 (16:52 +0000)
committerArt4 <art4@wlabs.de>
Mon, 13 Jan 2025 16:52:05 +0000 (16:52 +0000)
tests/Unit/Core/Logger/LoggerManagerTest.php

index 0dae2fcc6c8f650707cf4a719ff253e7ee9bb86e..02f9c0b2e28db07a836a4ffe5c47a096840d8933 100644 (file)
@@ -21,6 +21,23 @@ use Psr\Log\NullLogger;
 
 class LoggerManagerTest extends TestCase
 {
+       /**
+        * Clean the private static properties
+        *
+        * @see LoggerManager::$logger
+        * @see LoggerManager::$logChannel
+        */
+       protected function tearDown(): void
+       {
+               $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
+               $reflectionProperty->setAccessible(true);
+               $reflectionProperty->setValue(null, null);
+
+               $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logChannel');
+               $reflectionProperty->setAccessible(true);
+               $reflectionProperty->setValue(null, LogChannel::DEFAULT);
+       }
+
        public function testGetLoggerReturnsPsrLogger(): void
        {
                $factory = new LoggerManager(
@@ -29,10 +46,6 @@ class LoggerManagerTest extends TestCase
                );
 
                $this->assertInstanceOf(LoggerInterface::class, $factory->getLogger());
-
-               $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
-               $reflectionProperty->setAccessible(true);
-               $reflectionProperty->setValue(null, null);
        }
 
        public function testGetLoggerReturnsSameObject(): void
@@ -43,10 +56,6 @@ class LoggerManagerTest extends TestCase
                );
 
                $this->assertSame($factory->getLogger(), $factory->getLogger());
-
-               $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
-               $reflectionProperty->setAccessible(true);
-               $reflectionProperty->setValue(null, null);
        }
 
        public function testGetLoggerWithDebugDisabledReturnsNullLogger(): void
@@ -62,10 +71,6 @@ class LoggerManagerTest extends TestCase
                );
 
                $this->assertInstanceOf(NullLogger::class, $factory->getLogger());
-
-               $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
-               $reflectionProperty->setAccessible(true);
-               $reflectionProperty->setValue(null, null);
        }
 
        public function testGetLoggerWithProfilerEnabledReturnsProfilerLogger(): void
@@ -82,10 +87,6 @@ class LoggerManagerTest extends TestCase
                );
 
                $this->assertInstanceOf(ProfilerLogger::class, $factory->getLogger());
-
-               $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
-               $reflectionProperty->setAccessible(true);
-               $reflectionProperty->setValue(null, null);
        }
 
        public function testChangeLogChannelReturnsDifferentLogger(): void
@@ -106,10 +107,6 @@ class LoggerManagerTest extends TestCase
                $factory->changeLogChannel(LogChannel::CONSOLE);
 
                $this->assertNotSame($logger1, $factory->getLogger());
-
-               $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
-               $reflectionProperty->setAccessible(true);
-               $reflectionProperty->setValue(null, null);
        }
 
        public function testChangeLogChannelToWorkerReturnsWorkerLogger(): void
@@ -128,9 +125,5 @@ class LoggerManagerTest extends TestCase
                $factory->changeLogChannel(LogChannel::WORKER);
 
                $this->assertInstanceOf(WorkerLogger::class, $factory->getLogger());
-
-               $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
-               $reflectionProperty->setAccessible(true);
-               $reflectionProperty->setValue(null, null);
        }
 }