5
5
*/
6
6
namespace Magento \Developer \Test \Unit \Model \Logger \Handler ;
7
7
8
+ use Magento \Config \Setup \ConfigOptionsList ;
8
9
use Magento \Developer \Model \Logger \Handler \Debug ;
9
10
use Magento \Framework \App \Config \ScopeConfigInterface ;
10
11
use Magento \Framework \App \DeploymentConfig ;
11
12
use Magento \Framework \App \State ;
12
13
use Magento \Framework \Filesystem \DriverInterface ;
13
14
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
14
15
use Monolog \Formatter \FormatterInterface ;
16
+ use Monolog \Level ;
15
17
use Monolog \Logger ;
18
+ use Monolog \LogRecord ;
16
19
use PHPUnit \Framework \MockObject \MockObject ;
17
20
use PHPUnit \Framework \TestCase ;
18
21
@@ -51,6 +54,11 @@ class DebugTest extends TestCase
51
54
*/
52
55
private $ deploymentConfigMock ;
53
56
57
+ /**
58
+ * @var LogRecord
59
+ */
60
+ private $ logRecord ;
61
+
54
62
/**
55
63
* @inheritdoc
56
64
*/
@@ -81,6 +89,13 @@ protected function setUp(): void
81
89
'deploymentConfig ' => $ this ->deploymentConfigMock
82
90
]);
83
91
$ this ->model ->setFormatter ($ this ->formatterMock );
92
+
93
+ $ this ->logRecord = new LogRecord (
94
+ new \DateTimeImmutable (),
95
+ 'testChannel ' ,
96
+ Level::Debug,
97
+ 'testMessage '
98
+ );
84
99
}
85
100
86
101
/**
@@ -99,7 +114,7 @@ public function testHandleEnabledInDeveloperMode()
99
114
->expects ($ this ->never ())
100
115
->method ('getValue ' );
101
116
102
- $ this ->assertTrue ($ this ->model ->isHandling ([ ' formatted ' => false , ' level ' => Logger:: DEBUG ] ));
117
+ $ this ->assertTrue ($ this ->model ->isHandling ($ this -> logRecord ));
103
118
}
104
119
105
120
/**
@@ -118,7 +133,7 @@ public function testHandleEnabledInDefaultMode()
118
133
->expects ($ this ->never ())
119
134
->method ('getValue ' );
120
135
121
- $ this ->assertTrue ($ this ->model ->isHandling ([ ' formatted ' => false , ' level ' => Logger:: DEBUG ] ));
136
+ $ this ->assertTrue ($ this ->model ->isHandling ($ this -> logRecord ));
122
137
}
123
138
124
139
/**
@@ -137,7 +152,7 @@ public function testHandleDisabledByProduction()
137
152
->expects ($ this ->never ())
138
153
->method ('getValue ' );
139
154
140
- $ this ->assertFalse ($ this ->model ->isHandling ([ ' formatted ' => false , ' level ' => Logger:: DEBUG ] ));
155
+ $ this ->assertFalse ($ this ->model ->isHandling ($ this -> logRecord ));
141
156
}
142
157
143
158
/**
@@ -148,15 +163,19 @@ public function testHandleDisabledByLevel()
148
163
$ this ->deploymentConfigMock ->expects ($ this ->once ())
149
164
->method ('isAvailable ' )
150
165
->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 );
158
170
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
+ ));
160
179
}
161
180
162
181
/**
@@ -174,6 +193,6 @@ public function testDeploymentConfigIsNotAvailable()
174
193
->expects ($ this ->never ())
175
194
->method ('getValue ' );
176
195
177
- $ this ->assertTrue ($ this ->model ->isHandling ([ ' formatted ' => false , ' level ' => Logger:: DEBUG ] ));
196
+ $ this ->assertTrue ($ this ->model ->isHandling ($ this -> logRecord ));
178
197
}
179
198
}
0 commit comments