12
12
namespace Symfony \Bundle \MonologBundle \Tests \DependencyInjection ;
13
13
14
14
use InvalidArgumentException ;
15
+ use Monolog \Handler \FingersCrossed \ErrorLevelActivationStrategy ;
15
16
use Monolog \Handler \RollbarHandler ;
16
17
use Monolog \Logger ;
17
18
use Monolog \Processor \UidProcessor ;
19
+ use Symfony \Bridge \Monolog \Processor \SwitchUserTokenProcessor ;
18
20
use Symfony \Bundle \MonologBundle \DependencyInjection \MonologExtension ;
19
21
use Symfony \Bundle \MonologBundle \DependencyInjection \Compiler \LoggerChannelPass ;
20
22
use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -495,8 +497,27 @@ public function testLogglyHandler()
495
497
$ this ->assertDICDefinitionMethodCallAt (1 , $ handler , 'setTag ' , ['foo,bar ' ]);
496
498
}
497
499
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
+
498
510
/** @group legacy */
499
511
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 )
500
521
{
501
522
$ container = $ this ->getContainer ([['handlers ' => [
502
523
'main ' => ['type ' => 'fingers_crossed ' , 'handler ' => 'nested ' , 'excluded_404s ' => ['^/foo ' , '^/bar ' ]],
@@ -514,14 +535,33 @@ public function testFingersCrossedHandlerWhenExcluded404sAreSpecified()
514
535
515
536
$ strategy = $ container ->getDefinition ('monolog.handler.main.not_found_strategy ' );
516
537
$ 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 ]);
518
539
519
540
$ handler = $ container ->getDefinition ('monolog.handler.main ' );
520
541
$ this ->assertDICDefinitionClass ($ handler , 'Monolog\Handler\FingersCrossedHandler ' );
521
542
$ this ->assertDICConstructorArguments ($ handler , [new Reference ('monolog.handler.nested ' ), new Reference ('monolog.handler.main.not_found_strategy ' ), 0 , true , true , null ]);
522
543
}
523
544
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
+
524
555
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 )
525
565
{
526
566
if (!class_exists ('Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy ' )) {
527
567
$ this ->markTestSkipped ('Symfony Monolog 4.1+ is needed. ' );
@@ -554,7 +594,7 @@ public function testFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified()
554
594
['code ' => 404 , 'urls ' => []],
555
595
['code ' => 405 , 'urls ' => ['^/foo ' , '^/bar ' ]]
556
596
],
557
- \ Monolog \Logger:: WARNING
597
+ $ activation ,
558
598
]);
559
599
560
600
$ handler = $ container ->getDefinition ('monolog.handler.main ' );
0 commit comments