@@ -101,6 +101,72 @@ public static function provideVerbosityMappingTests(): array
101
101
];
102
102
}
103
103
104
+ /**
105
+ * @dataProvider provideHandleSilentTests
106
+ */
107
+ public function testHandleSilent ($ handleSilent , $ verbosity , $ level , $ isHandling , $ isBubbling , array $ map = [])
108
+ {
109
+ $ output = $ this ->createMock (OutputInterface::class);
110
+ $ output
111
+ ->expects ($ this ->atLeastOnce ())
112
+ ->method ('getVerbosity ' )
113
+ ->willReturn ($ verbosity )
114
+ ;
115
+ $ handler = new ConsoleHandler ($ output , false , $ map , handleSilent: $ handleSilent );
116
+ $ this ->assertSame ($ isHandling , $ handler ->isHandling (RecordFactory::create ($ level )),
117
+ '->isHandling returns correct value depending on console verbosity and log level '
118
+ );
119
+
120
+ // check that the handler actually outputs the record if it handles it at verbosity above SILENT
121
+ $ levelName = Logger::getLevelName ($ level );
122
+ $ levelName = \sprintf ('%-9s ' , $ levelName );
123
+
124
+ $ realOutput = $ this ->getMockBuilder (Output::class)->onlyMethods (['doWrite ' ])->getMock ();
125
+ $ realOutput ->setVerbosity ($ verbosity );
126
+ $ log = "16:21:54 $ levelName [app] My info message \n" ;
127
+ $ realOutput
128
+ ->expects ($ isHandling && $ verbosity > OutputInterface::VERBOSITY_SILENT ? $ this ->once () : $ this ->never ())
129
+ ->method ('doWrite ' )
130
+ ->with ($ log , false );
131
+ $ handler = new ConsoleHandler ($ realOutput , false , $ map , handleSilent: $ handleSilent );
132
+
133
+ $ infoRecord = RecordFactory::create ($ level , 'My info message ' , 'app ' , datetime: new \DateTimeImmutable ('2013-05-29 16:21:54 ' ));
134
+ $ this ->assertSame (!$ isBubbling , $ handler ->handle ($ infoRecord ),
135
+ 'The handler bubbled correctly when it did not output the message. '
136
+ );
137
+ }
138
+
139
+ public static function provideHandleSilentTests (): array
140
+ {
141
+ return [
142
+ [true , OutputInterface::VERBOSITY_SILENT , Level::Warning, true , false ],
143
+ [true , OutputInterface::VERBOSITY_NORMAL , Level::Warning, true , false ],
144
+ [true , OutputInterface::VERBOSITY_SILENT , Level::Warning, true , false , [
145
+ OutputInterface::VERBOSITY_SILENT => Level::Warning,
146
+ ]],
147
+ [true , OutputInterface::VERBOSITY_SILENT , Level::Warning, false , true , [
148
+ OutputInterface::VERBOSITY_SILENT => Level::Error,
149
+ ]],
150
+ [true , OutputInterface::VERBOSITY_SILENT , Level::Emergency, true , false ],
151
+ [true , OutputInterface::VERBOSITY_SILENT , Level::Emergency, true , false , [
152
+ OutputInterface::VERBOSITY_SILENT => Level::Emergency,
153
+ ]],
154
+ [false , OutputInterface::VERBOSITY_SILENT , Level::Warning, false , true ],
155
+ [false , OutputInterface::VERBOSITY_NORMAL , Level::Warning, true , false ],
156
+ [false , OutputInterface::VERBOSITY_SILENT , Level::Warning, true , false , [
157
+ OutputInterface::VERBOSITY_SILENT => Level::Warning,
158
+ ]],
159
+ [false , OutputInterface::VERBOSITY_SILENT , Level::Warning, false , true , [
160
+ OutputInterface::VERBOSITY_SILENT => Level::Error,
161
+ ]],
162
+ [false , OutputInterface::VERBOSITY_SILENT , Level::Emergency, false , true ],
163
+ [false , OutputInterface::VERBOSITY_SILENT , Level::Emergency, true , false , [
164
+ OutputInterface::VERBOSITY_SILENT => Level::Emergency,
165
+ ]],
166
+ ];
167
+ }
168
+
169
+
104
170
public function testVerbosityChanged ()
105
171
{
106
172
$ output = $ this ->createMock (OutputInterface::class);
0 commit comments