Skip to content

Commit df13f40

Browse files
[DI] Enhance logging in compiler passes
1 parent 9b84732 commit df13f40

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class UnusedTagsPass implements CompilerPassInterface
5353

5454
public function process(ContainerBuilder $container)
5555
{
56-
$compiler = $container->getCompiler();
57-
$formatter = $compiler->getLoggingFormatter();
5856
$tags = array_unique(array_merge($container->findTags(), $this->whitelist));
5957

6058
foreach ($container->findUnusedTags() as $tag) {
@@ -81,7 +79,7 @@ public function process(ContainerBuilder $container)
8179
$message .= sprintf(' Did you mean "%s"?', implode('", "', $candidates));
8280
}
8381

84-
$compiler->addLogMessage($formatter->format($this, $message));
82+
$container->log($this, $message);
8583
}
8684
}
8785
}

FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function build(ContainerBuilder $container)
104104
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
105105
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
106106
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
107-
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
107+
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING, -32);
108108
$container->addCompilerPass(new ConfigCachePass());
109109
$container->addCompilerPass(new CacheCollectorPass());
110110
}

Tests/DependencyInjection/Compiler/UnusedTagsPassTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,10 @@ public function testProcess()
1919
{
2020
$pass = new UnusedTagsPass();
2121

22-
$formatter = $this->getMockBuilder('Symfony\Component\DependencyInjection\Compiler\LoggingFormatter')->getMock();
23-
$formatter
24-
->expects($this->at(0))
25-
->method('format')
26-
->with($pass, 'Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?')
27-
;
28-
29-
$compiler = $this->getMockBuilder('Symfony\Component\DependencyInjection\Compiler\Compiler')->getMock();
30-
$compiler->expects($this->once())->method('getLoggingFormatter')->will($this->returnValue($formatter));
31-
32-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getCompiler', 'findUnusedTags', 'findTags'))->getMock();
33-
$container->expects($this->once())->method('getCompiler')->will($this->returnValue($compiler));
22+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'findUnusedTags', 'findTags', 'log'))->getMock();
23+
$container->expects($this->once())
24+
->method('log')
25+
->with($pass, 'Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?');
3426
$container->expects($this->once())
3527
->method('findTags')
3628
->will($this->returnValue(array('kenrel.event_subscriber')));

0 commit comments

Comments
 (0)