File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 26
26
],
27
27
"require" : {
28
28
"php" : " ^8.1" ,
29
- "monolog/monolog" : " ^2.9 || ^ 3.0" ,
29
+ "monolog/monolog" : " ^3.0" ,
30
30
"phpdocumentor/guides" : " ^1.0 || ^2.0" ,
31
31
"phpdocumentor/guides-restructured-text" : " ^1.0 || ^2.0" ,
32
32
"symfony/config" : " ^5.4 || ^6.3 || ^7.0" ,
Original file line number Diff line number Diff line change 13
13
14
14
namespace phpDocumentor \Guides \Cli \Logger ;
15
15
16
+ use Monolog \Level ;
16
17
use Monolog \LogRecord ;
17
18
use Monolog \Processor \ProcessorInterface ;
18
19
use Psr \Log \LogLevel ;
27
28
final class SpyProcessor implements ProcessorInterface
28
29
{
29
30
private bool $ hasBeenCalled = false ;
31
+ private Level $ level ;
30
32
31
- public function __construct (private string |null $ level = LogLevel::WARNING )
33
+ public function __construct (string |null $ level = LogLevel::WARNING )
32
34
{
35
+ if ($ level === null ) {
36
+ $ level = LogLevel::WARNING ;
37
+ }
38
+
39
+ $ this ->level = Level::fromName (strtolower ($ level ));
33
40
}
34
41
35
42
public function hasBeenCalled (): bool
@@ -39,7 +46,8 @@ public function hasBeenCalled(): bool
39
46
40
47
public function __invoke (array |LogRecord $ record ): array |LogRecord
41
48
{
42
- if (strtolower ($ record ['level_name ' ]) === $ this ->level ) {
49
+ $ recordLevel = Level::fromName ($ record ['level_name ' ]);
50
+ if ($ this ->level ->includes ($ recordLevel )) {
43
51
$ this ->hasBeenCalled = true ;
44
52
}
45
53
Original file line number Diff line number Diff line change 14
14
namespace phpDocumentor \Guides \Cli \Logger ;
15
15
16
16
use PHPUnit \Framework \TestCase ;
17
+ use Psr \Log \LogLevel ;
17
18
18
19
final class SpyProcessorTest extends TestCase
19
20
{
@@ -30,4 +31,18 @@ public function testItKnowsWhenALogIsEmitted(): void
30
31
$ process (['channel ' => 'test ' , 'level_name ' => 'warning ' ]);
31
32
self ::assertTrue ($ process ->hasBeenCalled ());
32
33
}
34
+
35
+ public function testItKnowsWhenAErrorIsEmitted (): void
36
+ {
37
+ $ process = new SpyProcessor ();
38
+ $ process (['channel ' => 'test ' , 'level_name ' => 'error ' ]);
39
+ self ::assertTrue ($ process ->hasBeenCalled ());
40
+ }
41
+
42
+ public function testIsNotCalledWhenLevelIsTolow (): void
43
+ {
44
+ $ process = new SpyProcessor (LogLevel::ERROR );
45
+ $ process (['channel ' => 'test ' , 'level_name ' => 'warning ' ]);
46
+ self ::assertFalse ($ process ->hasBeenCalled ());
47
+ }
33
48
}
You can’t perform that action at this time.
0 commit comments