From 08b4846e12c27a52c8d684691075395713f4d229 Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Wed, 14 May 2025 17:10:33 +0200 Subject: [PATCH 1/5] Allow setting priority for processors --- .../Compiler/AddProcessorsPass.php | 70 -------- .../Compiler/LoggerChannelPass.php | 69 ++++++++ MonologBundle.php | 2 - .../Compiler/AddProcessorsPassTest.php | 97 ----------- .../Compiler/LoggerChannelPassTest.php | 162 +++++++++++++++--- 5 files changed, 204 insertions(+), 196 deletions(-) delete mode 100644 DependencyInjection/Compiler/AddProcessorsPass.php delete mode 100644 Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php diff --git a/DependencyInjection/Compiler/AddProcessorsPass.php b/DependencyInjection/Compiler/AddProcessorsPass.php deleted file mode 100644 index cc99b67d..00000000 --- a/DependencyInjection/Compiler/AddProcessorsPass.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\ChildDefinition; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -/** - * Registers processors in Monolog loggers or handlers. - * - * @author Christophe Coevoet - * - * @internal since 3.9.0 - */ -class AddProcessorsPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container) - { - if (!$container->hasDefinition('monolog.logger')) { - return; - } - - foreach ($container->findTaggedServiceIds('monolog.processor') as $id => $tags) { - foreach ($tags as $tag) { - if (!empty($tag['channel']) && !empty($tag['handler'])) { - throw new \InvalidArgumentException(\sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $id)); - } - - if (!empty($tag['handler'])) { - $definition = $container->findDefinition(\sprintf('monolog.handler.%s', $tag['handler'])); - $parentDef = $definition; - while (!$parentDef->getClass() && $parentDef instanceof ChildDefinition) { - $parentDef = $container->findDefinition($parentDef->getParent()); - } - $class = $container->getParameterBag()->resolveValue($parentDef->getClass()); - if (!method_exists($class, 'pushProcessor')) { - throw new \InvalidArgumentException(\sprintf('The "%s" handler does not accept processors', $tag['handler'])); - } - } elseif (!empty($tag['channel'])) { - if ('app' === $tag['channel']) { - $definition = $container->getDefinition('monolog.logger'); - } else { - $definition = $container->getDefinition(\sprintf('monolog.logger.%s', $tag['channel'])); - } - } else { - $definition = $container->getDefinition('monolog.logger_prototype'); - } - - if (!empty($tag['method'])) { - $processor = [new Reference($id), $tag['method']]; - } else { - // If no method is defined, fallback to use __invoke - $processor = new Reference($id); - } - $definition->addMethodCall('pushProcessor', [$processor]); - } - } - } -} diff --git a/DependencyInjection/Compiler/LoggerChannelPass.php b/DependencyInjection/Compiler/LoggerChannelPass.php index 4c7b147c..28f4193f 100644 --- a/DependencyInjection/Compiler/LoggerChannelPass.php +++ b/DependencyInjection/Compiler/LoggerChannelPass.php @@ -13,8 +13,10 @@ use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\Argument\BoundArgument; +use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; @@ -28,6 +30,8 @@ */ class LoggerChannelPass implements CompilerPassInterface { + use PriorityTaggedServiceTrait; + protected $channels = ['app']; public function process(ContainerBuilder $container) @@ -103,6 +107,8 @@ public function process(ContainerBuilder $container) $logger->addMethodCall('pushHandler', [new Reference($handler)]); } } + + $this->addProcessors($container); } /** @@ -155,4 +161,67 @@ private function changeReference(Reference $reference, string $serviceId): Refer { return new Reference($serviceId, $reference->getInvalidBehavior()); } + + private function addProcessors(ContainerBuilder $container) + { + $indexedTags = []; + $i = 1; + + foreach ($container->findTaggedServiceIds('monolog.processor') as $id => $tags) { + foreach ($tags as &$tag) { + $indexedTags[$tag['index'] = $i++] = $tag; + } + unset($tag); + $definition = $container->getDefinition($id); + $definition->setTags(array_merge($definition->getTags(), ['monolog.processor' => $tags])); + } + + $taggedIteratorArgument = new TaggedIteratorArgument('monolog.processor', 'index', null, true); + // array_reverse is used because ProcessableHandlerTrait::pushProcessor prepends processors to the beginning of the stack + foreach (array_reverse($this->findAndSortTaggedServices($taggedIteratorArgument, $container), true) as $index => $reference) { + $tag = $indexedTags[$index]; + + if (!empty($tag['channel']) && !empty($tag['handler'])) { + throw new \InvalidArgumentException(\sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $reference)); + } + + if (!empty($tag['handler'])) { + $parentDef = $container->findDefinition(\sprintf('monolog.handler.%s', $tag['handler'])); + $definitions = [$parentDef]; + while (!$parentDef->getClass() && $parentDef instanceof ChildDefinition) { + $parentDef = $container->findDefinition($parentDef->getParent()); + } + $class = $container->getParameterBag()->resolveValue($parentDef->getClass()); + if (!method_exists($class, 'pushProcessor')) { + throw new \InvalidArgumentException(\sprintf('The "%s" handler does not accept processors', $tag['handler'])); + } + } elseif (!empty($tag['channel'])) { + if ('app' === $tag['channel']) { + $definitions = [$container->getDefinition('monolog.logger')]; + } else { + $definitions = [$container->getDefinition(\sprintf('monolog.logger.%s', $tag['channel']))]; + } + } else { + $definitions = [$container->getDefinition('monolog.logger')]; + foreach ($this->channels as $channel) { + if ('app' === $channel) { + continue; + } + + $definitions[] = $container->getDefinition(\sprintf('monolog.logger.%s', $channel)); + } + } + + if (!empty($tag['method'])) { + $processor = [$reference, $tag['method']]; + } else { + // If no method is defined, fallback to use __invoke + $processor = $reference; + } + + foreach ($definitions as $definition) { + $definition->addMethodCall('pushProcessor', [$processor]); + } + } + } } diff --git a/MonologBundle.php b/MonologBundle.php index baae67f2..a2cb4d63 100644 --- a/MonologBundle.php +++ b/MonologBundle.php @@ -14,7 +14,6 @@ use Monolog\Formatter\JsonFormatter; use Monolog\Formatter\LineFormatter; use Monolog\Handler\HandlerInterface; -use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddProcessorsPass; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddSwiftMailerTransportPass; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\FixEmptyLoggerPass; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; @@ -37,7 +36,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass($channelPass = new LoggerChannelPass()); $container->addCompilerPass(new FixEmptyLoggerPass($channelPass)); - $container->addCompilerPass(new AddProcessorsPass()); $container->addCompilerPass(new AddSwiftMailerTransportPass()); } diff --git a/Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php b/Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php deleted file mode 100644 index c11c2a33..00000000 --- a/Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler; - -use Monolog\Handler\NullHandler; -use Monolog\Logger; -use PHPUnit\Framework\TestCase; -use Symfony\Bridge\Monolog\Handler\ConsoleHandler; -use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddProcessorsPass; -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\DependencyInjection\Reference; - -class AddProcessorsPassTest extends TestCase -{ - public function testHandlerProcessors() - { - $container = $this->getContainer(); - - $service = $container->getDefinition('monolog.handler.test'); - $calls = $service->getMethodCalls(); - $this->assertCount(1, $calls); - $this->assertEquals(['pushProcessor', [new Reference('test')]], $calls[0]); - - $service = $container->getDefinition('handler_test'); - $calls = $service->getMethodCalls(); - $this->assertCount(1, $calls); - $this->assertEquals(['pushProcessor', [new Reference('test2')]], $calls[0]); - } - - public function testFailureOnHandlerWithoutPushProcessor() - { - $container = new ContainerBuilder(); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config')); - $loader->load('monolog.xml'); - - $service = new Definition(NullHandler::class); - $service->addTag('monolog.processor', ['handler' => 'test3']); - $container->setDefinition('monolog.handler.test3', $service); - - $container->getCompilerPassConfig()->setOptimizationPasses([]); - $container->getCompilerPassConfig()->setRemovingPasses([]); - $container->addCompilerPass(new AddProcessorsPass()); - - if (Logger::API < 2) { - $container->compile(); - $service = $container->getDefinition('monolog.handler.test3'); - $calls = $service->getMethodCalls(); - $this->assertCount(1, $calls); - } else { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The "test3" handler does not accept processors'); - $container->compile(); - } - } - - protected function getContainer() - { - $container = new ContainerBuilder(); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config')); - $loader->load('monolog.xml'); - - $definition = $container->getDefinition('monolog.logger_prototype'); - $container->setParameter('monolog.handler.console.class', ConsoleHandler::class); - $container->setDefinition('monolog.handler.test', new Definition('%monolog.handler.console.class%', [100, false])); - $container->setDefinition('handler_test', new Definition('%monolog.handler.console.class%', [100, false])); - $container->setAlias('monolog.handler.test2', 'handler_test'); - $definition->addMethodCall('pushHandler', [new Reference('monolog.handler.test')]); - $definition->addMethodCall('pushHandler', [new Reference('monolog.handler.test2')]); - - $service = new Definition('TestClass', ['false', new Reference('logger')]); - $service->addTag('monolog.processor', ['handler' => 'test']); - $container->setDefinition('test', $service); - - $service = new Definition('TestClass', ['false', new Reference('logger')]); - $service->addTag('monolog.processor', ['handler' => 'test2']); - $container->setDefinition('test2', $service); - - $container->getCompilerPassConfig()->setOptimizationPasses([]); - $container->getCompilerPassConfig()->setRemovingPasses([]); - $container->addCompilerPass(new AddProcessorsPass()); - $container->compile(); - - return $container; - } -} diff --git a/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php b/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php index 3b539e09..2f88a993 100644 --- a/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php +++ b/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php @@ -11,14 +11,18 @@ namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler; +use Monolog\Handler\NullHandler; +use Monolog\Logger; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; +use Symfony\Bridge\Monolog\Handler\ConsoleHandler; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\TypedReference; class LoggerChannelPassTest extends TestCase { @@ -30,28 +34,67 @@ public function testProcess() $service = $container->getDefinition('test'); $this->assertEquals('monolog.logger.test', (string) $service->getArgument(1), '->process replaces the logger by the new one'); - // pushHandlers for service "test" - $expected = [ - 'test' => ['monolog.handler.a', 'monolog.handler.b', 'monolog.handler.c'], - 'foo' => ['monolog.handler.b'], - 'bar' => ['monolog.handler.b', 'monolog.handler.c'], - ]; - - foreach ($expected as $serviceName => $handlers) { - $service = $container->getDefinition($serviceName); - $channel = $container->getDefinition((string) $service->getArgument(1)); - - $calls = $channel->getMethodCalls(); - $this->assertCount(\count($handlers), $calls); - foreach ($handlers as $i => $handler) { - [$methodName, $arguments] = $calls[$i]; - $this->assertEquals('pushHandler', $methodName); - $this->assertCount(1, $arguments); - $this->assertEquals($handler, (string) $arguments[0]); - } - } + $service = $container->getDefinition('test'); + $logger = $container->getDefinition((string) $service->getArgument(1)); + $calls = $logger->getMethodCalls(); + $this->assertCount(4, $calls); + $this->assertEquals(['pushHandler', [new Reference('monolog.handler.a')]], $calls[0]); + $this->assertEquals(['pushHandler', [new Reference('monolog.handler.b')]], $calls[1]); + $this->assertEquals(['pushHandler', [new Reference('monolog.handler.c')]], $calls[2]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.-10', 'SomeProcessor')]], $calls[3]); + + $service = $container->getDefinition('foo'); + $logger = $container->getDefinition((string) $service->getArgument(1)); + $calls = $logger->getMethodCalls(); + $this->assertCount(3, $calls); + $this->assertEquals(['pushHandler', [new Reference('monolog.handler.b')]], $calls[0]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.-10', 'SomeProcessor')]], $calls[1]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.foo+10', 'SomeProcessor')]], $calls[2]); + + $service = $container->getDefinition('bar'); + $logger = $container->getDefinition((string) $service->getArgument(1)); + $calls = $logger->getMethodCalls(); + $this->assertCount(3, $calls); + $this->assertEquals(['pushHandler', [new Reference('monolog.handler.b')]], $calls[0]); + $this->assertEquals(['pushHandler', [new Reference('monolog.handler.c')]], $calls[1]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.-10', 'SomeProcessor')]], $calls[2]); + + $logger = $container->getDefinition('monolog.logger'); + $calls = $logger->getMethodCalls(); + $this->assertCount(5, $calls); + $this->assertEquals(['useMicrosecondTimestamps', ['%monolog.use_microseconds%']], $calls[0]); + $this->assertEquals(['pushHandler', [new Reference('monolog.handler.b')]], $calls[1]); + $this->assertEquals(['pushHandler', [new Reference('monolog.handler.c')]], $calls[2]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.-10', 'SomeProcessor')]], $calls[3]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.app', 'SomeProcessor')]], $calls[4]); $this->assertNotNull($container->getDefinition('monolog.logger.additional')); + + $handler = $container->getDefinition('monolog.handler.test'); + $calls = $handler->getMethodCalls(); + $this->assertCount(1, $calls); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.a', 'SomeProcessor')]], $calls[0]); + + $handler = $container->getDefinition('handler_test'); + $calls = $handler->getMethodCalls(); + $this->assertCount(1, $calls); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.b', 'SomeProcessor')]], $calls[0]); + + $handler = $container->getDefinition('monolog.handler.a'); + $calls = $handler->getMethodCalls(); + $this->assertCount(5, $calls); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.-10', 'SomeProcessor')]], $calls[0]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.+10', 'SomeProcessor')]], $calls[1]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.+20', 'SomeProcessor')]], $calls[2]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.+20', 'SomeProcessor')]], $calls[2]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.+25+35', 'SomeProcessor')]], $calls[3]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.+35+25', 'SomeProcessor')]], $calls[4]); + + $handler = $container->getDefinition('monolog.handler.b'); + $calls = $handler->getMethodCalls(); + $this->assertCount(2, $calls); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.+35+25', 'SomeProcessor')]], $calls[0]); + $this->assertEquals(['pushProcessor', [new TypedReference('monolog.processor.handler.+25+35', 'SomeProcessor')]], $calls[1]); } public function testTypeHintedAliasesExistForEachChannel() @@ -144,23 +187,45 @@ public function testChannelsConfigurationOptionSupportsAppChannel() $this->addToAssertionCount(1); } + public function testFailureOnHandlerWithoutPushProcessor() + { + $container = $this->getFunctionalContainer(); + + $service = new Definition(NullHandler::class); + $service->addTag('monolog.processor', ['handler' => 'test3']); + $container->setDefinition('monolog.handler.test3', $service); + + if (Logger::API < 2) { + $container->compile(); + $service = $container->getDefinition('monolog.handler.test3'); + $calls = $service->getMethodCalls(); + $this->assertCount(1, $calls); + } else { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The "test3" handler does not accept processors'); + $container->compile(); + } + } + private function getContainer() { $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config')); $loader->load('monolog.xml'); $definition = $container->getDefinition('monolog.logger_prototype'); - $container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', [100, false])); + $container->setDefinition('monolog.handler.test', new Definition(ConsoleHandler::class)); + $container->setDefinition('handler_test', new Definition(ConsoleHandler::class)); + $container->setAlias('monolog.handler.test2', 'handler_test'); $definition->addMethodCall('pushHandler', [new Reference('monolog.handler.test')]); // Handlers - $container->set('monolog.handler.a', new Definition('%monolog.handler.null.class%', [100, false])); - $container->set('monolog.handler.b', new Definition('%monolog.handler.null.class%', [100, false])); - $container->set('monolog.handler.c', new Definition('%monolog.handler.null.class%', [100, false])); + $container->setDefinition('monolog.handler.a', new Definition(ConsoleHandler::class)); + $container->setDefinition('monolog.handler.b', new Definition(ConsoleHandler::class)); + $container->setDefinition('monolog.handler.c', new Definition(ConsoleHandler::class)); // Channels foreach (['test', 'foo', 'bar'] as $name) { - $service = new Definition('TestClass', ['false', new Reference('logger')]); + $service = new Definition('SomeClass', ['false', new Reference('logger')]); $service->addTag('monolog.logger', ['channel' => $name]); $container->setDefinition($name, $service); } @@ -178,6 +243,49 @@ private function getContainer() ], ]); + // Processors + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['handler' => 'test']); + $container->setDefinition('monolog.processor.handler.a', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['handler' => 'test2']); + $container->setDefinition('monolog.processor.handler.b', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['handler' => 'a', 'priority' => 10]); + $container->setDefinition('monolog.processor.handler.+10', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['handler' => 'a', 'priority' => -10]); + $container->setDefinition('monolog.processor.handler.-10', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['handler' => 'a', 'priority' => 20]); + $container->setDefinition('monolog.processor.handler.+20', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['handler' => 'a', 'priority' => 35]); + $service->addTag('monolog.processor', ['handler' => 'b', 'priority' => 25]); + $container->setDefinition('monolog.processor.handler.+35+25', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['handler' => 'a', 'priority' => 25]); + $service->addTag('monolog.processor', ['handler' => 'b', 'priority' => 35]); + $container->setDefinition('monolog.processor.handler.+25+35', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['priority' => -10]); + $container->setDefinition('monolog.processor.-10', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['channel' => 'app']); + $container->setDefinition('monolog.processor.app', $service); + + $service = new Definition('SomeProcessor'); + $service->addTag('monolog.processor', ['channel' => 'foo', 'priority' => 10]); + $container->setDefinition('monolog.processor.foo+10', $service); + $container->getCompilerPassConfig()->setOptimizationPasses([]); $container->getCompilerPassConfig()->setRemovingPasses([]); $container->addCompilerPass(new LoggerChannelPass()); @@ -192,11 +300,11 @@ private function getContainerWithSetter() $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config')); $loader->load('monolog.xml'); $definition = $container->getDefinition('monolog.logger_prototype'); - $container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', [100, false])); + $container->setDefinition('monolog.handler.test', new Definition(ConsoleHandler::class)); $definition->addMethodCall('pushHandler', [new Reference('monolog.handler.test')]); // Channels - $service = new Definition('TestClass'); + $service = new Definition('SomeClass'); $service->addTag('monolog.logger', ['channel' => 'test']); $service->addMethodCall('setLogger', [new Reference('logger')]); $container->setDefinition('foo', $service); From 95da1b1b2297cb2c6f84bcb27416437a66b77dbc Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Wed, 14 May 2025 20:32:11 +0200 Subject: [PATCH 2/5] -fix tests --- Tests/DependencyInjection/MonologExtensionTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php index eb02825f..8ed7eb59 100644 --- a/Tests/DependencyInjection/MonologExtensionTest.php +++ b/Tests/DependencyInjection/MonologExtensionTest.php @@ -17,6 +17,7 @@ use Monolog\Handler\RollbarHandler; use Monolog\Logger; use Monolog\Processor\UidProcessor; +use Symfony\Bridge\Monolog\Handler\ConsoleHandler; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessor; @@ -776,6 +777,7 @@ public function testAsMonologProcessorAutoconfiguration(): void } $container = $this->getContainer([], [ + 'monolog.logger.ccc_channel' => (new Definition(Logger::class))->setAutoconfigured(true), FooProcessor::class => (new Definition(FooProcessor::class))->setAutoconfigured(true), ]); @@ -803,6 +805,8 @@ public function testAsMonologProcessorAutoconfigurationWithPriority(): void } $container = $this->getContainer([], [ + 'monolog.handler.foo_handler' => (new Definition(ConsoleHandler::class))->setAutoconfigured(true), + 'monolog.logger.ccc_channel' => (new Definition(Logger::class))->setAutoconfigured(true), FooProcessorWithPriority::class => (new Definition(FooProcessorWithPriority::class))->setAutoconfigured(true), ]); @@ -812,12 +816,14 @@ public function testAsMonologProcessorAutoconfigurationWithPriority(): void 'handler' => 'foo_handler', 'method' => null, 'priority' => null, + 'index' => 1, ], [ 'channel' => 'ccc_channel', 'handler' => null, 'method' => '__invoke', 'priority' => 10, + 'index' => 2, ], ], $container->getDefinition(FooProcessorWithPriority::class)->getTag('monolog.processor')); } From ff00ae474dcdbee37b1f57096b8e30d1059680ba Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Wed, 14 May 2025 20:33:20 +0200 Subject: [PATCH 3/5] -fix tests --- Tests/DependencyInjection/MonologExtensionTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php index 8ed7eb59..389dcb6b 100644 --- a/Tests/DependencyInjection/MonologExtensionTest.php +++ b/Tests/DependencyInjection/MonologExtensionTest.php @@ -777,6 +777,7 @@ public function testAsMonologProcessorAutoconfiguration(): void } $container = $this->getContainer([], [ + 'monolog.handler.foo_handler' => (new Definition(ConsoleHandler::class))->setAutoconfigured(true), 'monolog.logger.ccc_channel' => (new Definition(Logger::class))->setAutoconfigured(true), FooProcessor::class => (new Definition(FooProcessor::class))->setAutoconfigured(true), ]); From 57e7a14efc9fb5a6842a25dc3e43af00e36b182d Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Wed, 14 May 2025 20:34:33 +0200 Subject: [PATCH 4/5] -fix tests --- Tests/DependencyInjection/MonologExtensionTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php index 389dcb6b..ce0820d1 100644 --- a/Tests/DependencyInjection/MonologExtensionTest.php +++ b/Tests/DependencyInjection/MonologExtensionTest.php @@ -787,11 +787,13 @@ public function testAsMonologProcessorAutoconfiguration(): void 'channel' => null, 'handler' => 'foo_handler', 'method' => null, + 'index' => 1 ], [ 'channel' => 'ccc_channel', 'handler' => null, 'method' => '__invoke', + 'index' => 2 ], ], $container->getDefinition(FooProcessor::class)->getTag('monolog.processor')); } From 6b7781b1f3a7f6c9245269a219118d9afca8a417 Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Wed, 14 May 2025 20:35:24 +0200 Subject: [PATCH 5/5] -fix code style --- Tests/DependencyInjection/MonologExtensionTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php index ce0820d1..82f8ef11 100644 --- a/Tests/DependencyInjection/MonologExtensionTest.php +++ b/Tests/DependencyInjection/MonologExtensionTest.php @@ -787,13 +787,13 @@ public function testAsMonologProcessorAutoconfiguration(): void 'channel' => null, 'handler' => 'foo_handler', 'method' => null, - 'index' => 1 + 'index' => 1, ], [ 'channel' => 'ccc_channel', 'handler' => null, 'method' => '__invoke', - 'index' => 2 + 'index' => 2, ], ], $container->getDefinition(FooProcessor::class)->getTag('monolog.processor')); }