55 */
66namespace Magento \Developer \Test \Unit \Model \Logger \Handler ;
77
8+ use Magento \Config \Setup \ConfigOptionsList ;
89use Magento \Developer \Model \Logger \Handler \Debug ;
910use Magento \Framework \App \Config \ScopeConfigInterface ;
1011use Magento \Framework \App \DeploymentConfig ;
1112use Magento \Framework \App \State ;
1213use Magento \Framework \Filesystem \DriverInterface ;
1314use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1415use Monolog \Formatter \FormatterInterface ;
16+ use Monolog \Level ;
1517use Monolog \Logger ;
18+ use Monolog \LogRecord ;
1619use PHPUnit \Framework \MockObject \MockObject ;
1720use PHPUnit \Framework \TestCase ;
1821
@@ -51,6 +54,11 @@ class DebugTest extends TestCase
5154 */
5255 private $ deploymentConfigMock ;
5356
57+ /**
58+ * @var LogRecord
59+ */
60+ private $ logRecord ;
61+
5462 /**
5563 * @inheritdoc
5664 */
@@ -81,6 +89,13 @@ protected function setUp(): void
8189 'deploymentConfig ' => $ this ->deploymentConfigMock
8290 ]);
8391 $ this ->model ->setFormatter ($ this ->formatterMock );
92+
93+ $ this ->logRecord = new LogRecord (
94+ new \DateTimeImmutable (),
95+ 'testChannel ' ,
96+ Level::Debug,
97+ 'testMessage '
98+ );
8499 }
85100
86101 /**
@@ -99,7 +114,7 @@ public function testHandleEnabledInDeveloperMode()
99114 ->expects ($ this ->never ())
100115 ->method ('getValue ' );
101116
102- $ this ->assertTrue ($ this ->model ->isHandling ([ ' formatted ' => false , ' level ' => Logger:: DEBUG ] ));
117+ $ this ->assertTrue ($ this ->model ->isHandling ($ this -> logRecord ));
103118 }
104119
105120 /**
@@ -118,7 +133,7 @@ public function testHandleEnabledInDefaultMode()
118133 ->expects ($ this ->never ())
119134 ->method ('getValue ' );
120135
121- $ this ->assertTrue ($ this ->model ->isHandling ([ ' formatted ' => false , ' level ' => Logger:: DEBUG ] ));
136+ $ this ->assertTrue ($ this ->model ->isHandling ($ this -> logRecord ));
122137 }
123138
124139 /**
@@ -137,7 +152,7 @@ public function testHandleDisabledByProduction()
137152 ->expects ($ this ->never ())
138153 ->method ('getValue ' );
139154
140- $ this ->assertFalse ($ this ->model ->isHandling ([ ' formatted ' => false , ' level ' => Logger:: DEBUG ] ));
155+ $ this ->assertFalse ($ this ->model ->isHandling ($ this -> logRecord ));
141156 }
142157
143158 /**
@@ -148,15 +163,19 @@ public function testHandleDisabledByLevel()
148163 $ this ->deploymentConfigMock ->expects ($ this ->once ())
149164 ->method ('isAvailable ' )
150165 ->willReturn (true );
151- $ this ->stateMock
152- ->expects ($ this ->never ())
153- ->method ('getMode ' )
154- ->willReturn (State::MODE_DEVELOPER );
155- $ this ->scopeConfigMock
156- ->expects ($ this ->never ())
157- ->method ('getValue ' );
166+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
167+ ->method ('get ' )
168+ ->with (ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING )
169+ ->willReturn (false );
158170
159- $ this ->assertFalse ($ this ->model ->isHandling (['formatted ' => false , 'level ' => Logger::API ]));
171+ $ this ->assertFalse ($ this ->model ->isHandling (
172+ new LogRecord (
173+ new \DateTimeImmutable (),
174+ 'testChannel ' ,
175+ Level::Error,
176+ 'testMessage '
177+ )
178+ ));
160179 }
161180
162181 /**
@@ -174,6 +193,6 @@ public function testDeploymentConfigIsNotAvailable()
174193 ->expects ($ this ->never ())
175194 ->method ('getValue ' );
176195
177- $ this ->assertTrue ($ this ->model ->isHandling ([ ' formatted ' => false , ' level ' => Logger:: DEBUG ] ));
196+ $ this ->assertTrue ($ this ->model ->isHandling ($ this -> logRecord ));
178197 }
179198}
0 commit comments