Skip to content

Commit d02ca25

Browse files
committed
[MonologBundle] Fixed a bug when adding a processor on a service handler
1 parent 2f33b5d commit d02ca25

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/AddProcessorsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function process(ContainerBuilder $container)
3535
}
3636

3737
if (!empty($tag['handler'])) {
38-
$definition = $container->getDefinition(sprintf('monolog.handler.%s', $tag['handler']));
38+
$definition = $container->findDefinition(sprintf('monolog.handler.%s', $tag['handler']));
3939
} elseif (!empty($tag['channel'])) {
4040
if ('app' === $tag['channel']) {
4141
$definition = $container->getDefinition('monolog.logger');
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler;
13+
14+
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddProcessorsPass;
15+
use Symfony\Bundle\MonologBundle\Tests\TestCase;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\DependencyInjection\Definition;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\Config\FileLocator;
20+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
21+
22+
class AddProcessorsPassTest extends TestCase
23+
{
24+
public function testHandlerProcessors()
25+
{
26+
$container = $this->getContainer();
27+
28+
$service = $container->getDefinition('monolog.handler.test');
29+
$calls = $service->getMethodCalls();
30+
$this->assertCount(1, $calls);
31+
$this->assertEquals(array('pushProcessor', array(new Reference('test'))), $calls[0]);
32+
33+
$service = $container->getDefinition('handler_test');
34+
$calls = $service->getMethodCalls();
35+
$this->assertCount(1, $calls);
36+
$this->assertEquals(array('pushProcessor', array(new Reference('test2'))), $calls[0]);
37+
}
38+
39+
protected function getContainer()
40+
{
41+
$container = new ContainerBuilder();
42+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
43+
$loader->load('monolog.xml');
44+
45+
$definition = $container->getDefinition('monolog.logger_prototype');
46+
$container->setDefinition('monolog.handler.test', new Definition('%monolog.handler.null.class%', array (100, false)));
47+
$container->setDefinition('handler_test', new Definition('%monolog.handler.null.class%', array (100, false)));
48+
$container->setAlias('monolog.handler.test2', 'handler_test');
49+
$definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test')));
50+
$definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test2')));
51+
52+
$service = new Definition('TestClass', array('false', new Reference('logger')));
53+
$service->addTag('monolog.processor', array ('handler' => 'test'));
54+
$container->setDefinition('test', $service);
55+
56+
$service = new Definition('TestClass', array('false', new Reference('logger')));
57+
$service->addTag('monolog.processor', array ('handler' => 'test2'));
58+
$container->setDefinition('test2', $service);
59+
60+
$container->getCompilerPassConfig()->setOptimizationPasses(array());
61+
$container->getCompilerPassConfig()->setRemovingPasses(array());
62+
$container->addCompilerPass(new AddProcessorsPass());
63+
$container->compile();
64+
65+
return $container;
66+
}
67+
}

0 commit comments

Comments
 (0)