1212namespace Symfony \Bundle \MonologBundle \Tests \DependencyInjection ;
1313
1414use InvalidArgumentException ;
15+ use Monolog \Handler \FingersCrossed \ErrorLevelActivationStrategy ;
1516use Monolog \Handler \RollbarHandler ;
1617use Monolog \Logger ;
1718use Monolog \Processor \UidProcessor ;
19+ use Symfony \Bridge \Monolog \Processor \SwitchUserTokenProcessor ;
1820use Symfony \Bundle \MonologBundle \DependencyInjection \MonologExtension ;
1921use Symfony \Bundle \MonologBundle \DependencyInjection \Compiler \LoggerChannelPass ;
2022use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -495,8 +497,27 @@ public function testLogglyHandler()
495497 $ this ->assertDICDefinitionMethodCallAt (1 , $ handler , 'setTag ' , ['foo,bar ' ]);
496498 }
497499
500+ /** @group legacy */
501+ public function testLegacyFingersCrossedHandlerWhenExcluded404sAreSpecified ()
502+ {
503+ if (class_exists (SwitchUserTokenProcessor::class)) {
504+ $ this ->markTestSkipped ('Symfony MonologBridge < 5.2 is needed. ' );
505+ }
506+
507+ $ this ->doTestFingersCrossedHandlerWhenExcluded404sAreSpecified (\Monolog \Logger::WARNING );
508+ }
509+
498510 /** @group legacy */
499511 public function testFingersCrossedHandlerWhenExcluded404sAreSpecified ()
512+ {
513+ if (!class_exists (SwitchUserTokenProcessor::class)) {
514+ $ this ->markTestSkipped ('Symfony MonologBridge >= 5.2 is needed. ' );
515+ }
516+
517+ $ this ->doTestFingersCrossedHandlerWhenExcluded404sAreSpecified (new Definition (ErrorLevelActivationStrategy::class, [\Monolog \Logger::WARNING ]));
518+ }
519+
520+ private function doTestFingersCrossedHandlerWhenExcluded404sAreSpecified ($ activation )
500521 {
501522 $ container = $ this ->getContainer ([['handlers ' => [
502523 'main ' => ['type ' => 'fingers_crossed ' , 'handler ' => 'nested ' , 'excluded_404s ' => ['^/foo ' , '^/bar ' ]],
@@ -514,14 +535,33 @@ public function testFingersCrossedHandlerWhenExcluded404sAreSpecified()
514535
515536 $ strategy = $ container ->getDefinition ('monolog.handler.main.not_found_strategy ' );
516537 $ this ->assertDICDefinitionClass ($ strategy , 'Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategy ' );
517- $ this ->assertDICConstructorArguments ($ strategy , [new Reference ('request_stack ' ), ['^/foo ' , '^/bar ' ], \ Monolog \Logger:: WARNING ]);
538+ $ this ->assertDICConstructorArguments ($ strategy , [new Reference ('request_stack ' ), ['^/foo ' , '^/bar ' ], $ activation ]);
518539
519540 $ handler = $ container ->getDefinition ('monolog.handler.main ' );
520541 $ this ->assertDICDefinitionClass ($ handler , 'Monolog\Handler\FingersCrossedHandler ' );
521542 $ this ->assertDICConstructorArguments ($ handler , [new Reference ('monolog.handler.nested ' ), new Reference ('monolog.handler.main.not_found_strategy ' ), 0 , true , true , null ]);
522543 }
523544
545+ /** @group legacy */
546+ public function testLegacyFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified ()
547+ {
548+ if (class_exists (SwitchUserTokenProcessor::class)) {
549+ $ this ->markTestSkipped ('Symfony MonologBridge < 5.2 is needed. ' );
550+ }
551+
552+ $ this ->doTestFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified (\Monolog \Logger::WARNING );
553+ }
554+
524555 public function testFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified ()
556+ {
557+ if (!class_exists (SwitchUserTokenProcessor::class)) {
558+ $ this ->markTestSkipped ('Symfony MonologBridge >= 5.2 is needed. ' );
559+ }
560+
561+ $ this ->doTestFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified (new Definition (ErrorLevelActivationStrategy::class, [\Monolog \Logger::WARNING ]));
562+ }
563+
564+ private function doTestFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified ($ activation )
525565 {
526566 if (!class_exists ('Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy ' )) {
527567 $ this ->markTestSkipped ('Symfony Monolog 4.1+ is needed. ' );
@@ -554,7 +594,7 @@ public function testFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified()
554594 ['code ' => 404 , 'urls ' => []],
555595 ['code ' => 405 , 'urls ' => ['^/foo ' , '^/bar ' ]]
556596 ],
557- \ Monolog \Logger:: WARNING
597+ $ activation ,
558598 ]);
559599
560600 $ handler = $ container ->getDefinition ('monolog.handler.main ' );
0 commit comments