LoggerChannelPassTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler;
  11. use Symfony\Bundle\MonologBundle\Tests\TestCase;
  12. use Symfony\Component\DependencyInjection\Reference;
  13. use Symfony\Component\DependencyInjection\Definition;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
  16. use Symfony\Component\Config\FileLocator;
  17. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  18. class LoggerChannelPassTest extends TestCase
  19. {
  20. public function testProcess()
  21. {
  22. $container = $this->getContainer();
  23. $this->assertTrue($container->hasDefinition('monolog.logger.test'), '->process adds a logger service for tagged service');
  24. $service = $container->getDefinition('test');
  25. $this->assertEquals('monolog.logger.test', (string) $service->getArgument(1), '->process replaces the logger by the new one');
  26. }
  27. protected function getContainer()
  28. {
  29. $container = new ContainerBuilder();
  30. $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
  31. $loader->load('monolog.xml');
  32. $definition = $container->getDefinition('monolog.logger_prototype');
  33. $container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', array (100, false)));
  34. $definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test')));
  35. $service = new Definition('TestClass', array('false', new Reference('logger')));
  36. $service->addTag('monolog.logger', array ('channel' => 'test'));
  37. $container->setDefinition('test', $service);
  38. $container->getCompilerPassConfig()->setOptimizationPasses(array());
  39. $container->getCompilerPassConfig()->setRemovingPasses(array());
  40. $container->addCompilerPass(new LoggerChannelPass());
  41. $container->compile();
  42. return $container;
  43. }
  44. }