|
| 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