TranslationPassTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Component\Translation\Tests\DependencyInjection;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Definition;
  15. use Symfony\Component\DependencyInjection\Reference;
  16. use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
  17. class TranslationPassTest extends TestCase
  18. {
  19. public function testValidCollector()
  20. {
  21. $loader = (new Definition())
  22. ->addTag('translation.loader', ['alias' => 'xliff', 'legacy-alias' => 'xlf']);
  23. $reader = new Definition();
  24. $translator = (new Definition())
  25. ->setArguments([null, null, null, null]);
  26. $container = new ContainerBuilder();
  27. $container->setDefinition('translator.default', $translator);
  28. $container->setDefinition('translation.reader', $reader);
  29. $container->setDefinition('translation.xliff_loader', $loader);
  30. $pass = new TranslatorPass('translator.default', 'translation.reader');
  31. $pass->process($container);
  32. $expectedReader = (new Definition())
  33. ->addMethodCall('addLoader', ['xliff', new Reference('translation.xliff_loader')])
  34. ->addMethodCall('addLoader', ['xlf', new Reference('translation.xliff_loader')])
  35. ;
  36. $this->assertEquals($expectedReader, $reader);
  37. $expectedLoader = (new Definition())
  38. ->addTag('translation.loader', ['alias' => 'xliff', 'legacy-alias' => 'xlf'])
  39. ;
  40. $this->assertEquals($expectedLoader, $loader);
  41. $this->assertSame(['translation.xliff_loader' => ['xliff', 'xlf']], $translator->getArgument(3));
  42. $expected = ['translation.xliff_loader' => new ServiceClosureArgument(new Reference('translation.xliff_loader'))];
  43. $this->assertEquals($expected, $container->getDefinition((string) $translator->getArgument(0))->getArgument(0));
  44. }
  45. }