From 39088ab003b2af862209ba777276577d6325619c Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 13 Jan 2025 16:41:35 +0000 Subject: [PATCH] Clean static private properties of LoggerManager after test --- tests/Unit/Core/Logger/LoggerManagerTest.php | 48 ++++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/Unit/Core/Logger/LoggerManagerTest.php b/tests/Unit/Core/Logger/LoggerManagerTest.php index 14db1c2676..0dae2fcc6c 100644 --- a/tests/Unit/Core/Logger/LoggerManagerTest.php +++ b/tests/Unit/Core/Logger/LoggerManagerTest.php @@ -23,30 +23,30 @@ class LoggerManagerTest extends TestCase { public function testGetLoggerReturnsPsrLogger(): void { - $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue(null, null); - $factory = new LoggerManager( $this->createStub(IManageConfigValues::class), $this->createStub(LoggerFactory::class) ); $this->assertInstanceOf(LoggerInterface::class, $factory->getLogger()); + + $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue(null, null); } public function testGetLoggerReturnsSameObject(): void { - $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue(null, null); - $factory = new LoggerManager( $this->createStub(IManageConfigValues::class), $this->createStub(LoggerFactory::class) ); $this->assertSame($factory->getLogger(), $factory->getLogger()); + + $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue(null, null); } public function testGetLoggerWithDebugDisabledReturnsNullLogger(): void @@ -56,16 +56,16 @@ class LoggerManagerTest extends TestCase ['system', 'debugging', null, false], ]); - $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue(null, null); - $factory = new LoggerManager( $config, $this->createStub(LoggerFactory::class) ); $this->assertInstanceOf(NullLogger::class, $factory->getLogger()); + + $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue(null, null); } public function testGetLoggerWithProfilerEnabledReturnsProfilerLogger(): void @@ -76,16 +76,16 @@ class LoggerManagerTest extends TestCase ['system', 'profiling', null, true], ]); - $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue(null, null); - $factory = new LoggerManager( $config, $this->createStub(LoggerFactory::class) ); $this->assertInstanceOf(ProfilerLogger::class, $factory->getLogger()); + + $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue(null, null); } public function testChangeLogChannelReturnsDifferentLogger(): void @@ -96,10 +96,6 @@ class LoggerManagerTest extends TestCase ['system', 'profiling', null, true], ]); - $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue(null, null); - $factory = new LoggerManager( $config, $this->createStub(LoggerFactory::class) @@ -110,6 +106,10 @@ 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 @@ -120,10 +120,6 @@ class LoggerManagerTest extends TestCase ['system', 'profiling', null, true], ]); - $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue(null, null); - $factory = new LoggerManager( $config, $this->createStub(LoggerFactory::class) @@ -132,5 +128,9 @@ 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); } }