LoggingTranslatorPassTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\FrameworkBundle\Tests\DependencyInjection\Compiler;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. class LoggingTranslatorPassTest extends TestCase
  16. {
  17. public function testProcess()
  18. {
  19. $container = new ContainerBuilder();
  20. $container->setParameter('translator.logging', true);
  21. $container->setParameter('translator.class', 'Symfony\Component\Translation\Translator');
  22. $container->register('monolog.logger');
  23. $container->setAlias('logger', 'monolog.logger');
  24. $container->register('translator.default', '%translator.class%');
  25. $container->register('translator.logging', '%translator.class%');
  26. $container->setAlias('translator', 'translator.default');
  27. $translationWarmerDefinition = $container->register('translation.warmer')->addArgument(new Reference('translator'));
  28. $pass = new LoggingTranslatorPass();
  29. $pass->process($container);
  30. $this->assertEquals(new Reference('translator.logging.inner'), $translationWarmerDefinition->getArgument(0));
  31. }
  32. public function testThatCompilerPassIsIgnoredIfThereIsNotLoggerDefinition()
  33. {
  34. $container = new ContainerBuilder();
  35. $container->register('identity_translator');
  36. $container->setAlias('translator', 'identity_translator');
  37. $pass = new LoggingTranslatorPass();
  38. $pass->process($container);
  39. // we just check that the compiler pass does not break if a logger is not registered
  40. $this->addToAssertionCount(1);
  41. }
  42. public function testThatCompilerPassIsIgnoredIfThereIsNotTranslatorDefinition()
  43. {
  44. $container = new ContainerBuilder();
  45. $container->register('monolog.logger');
  46. $container->setAlias('logger', 'monolog.logger');
  47. $pass = new LoggingTranslatorPass();
  48. $pass->process($container);
  49. // we just check that the compiler pass does not break if a translator is not registered
  50. $this->addToAssertionCount(1);
  51. }
  52. }