|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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\FrameworkBundle\Tests\DependencyInjection\Compiler; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass; |
| 15 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | +use Symfony\Component\DependencyInjection\Reference; |
| 17 | +use Symfony\Component\Translation\TranslatorInterface; |
| 18 | + |
| 19 | +class DataCollectorTranslatorPassTest extends \PHPUnit_Framework_TestCase |
| 20 | +{ |
| 21 | + private $container; |
| 22 | + private $dataCollectorTranslatorPass; |
| 23 | + |
| 24 | + protected function setUp() |
| 25 | + { |
| 26 | + $this->container = new ContainerBuilder(); |
| 27 | + $this->dataCollectorTranslatorPass = new DataCollectorTranslatorPass(); |
| 28 | + |
| 29 | + $this->container->register('translator.data_collector', 'Symfony\Component\Translation\DataCollectorTranslator') |
| 30 | + ->setPublic(false) |
| 31 | + ->setDecoratedService('translator') |
| 32 | + ->setArguments(array(new Reference('translator.data_collector.inner'))) |
| 33 | + ; |
| 34 | + |
| 35 | + $this->container->register('data_collector.translation', 'Symfony\Component\Translation\DataCollector\TranslationDataCollector') |
| 36 | + ->setArguments(array(new Reference('translator.data_collector'))) |
| 37 | + ; |
| 38 | + } |
| 39 | + |
| 40 | + public function testProcessKeepsDataCollectorTranslatorIfItImplementsTranslatorBagInterface() |
| 41 | + { |
| 42 | + $this->container->register('translator', 'Symfony\Component\Translation\Translator'); |
| 43 | + |
| 44 | + $this->dataCollectorTranslatorPass->process($this->container); |
| 45 | + |
| 46 | + $this->assertTrue($this->container->hasDefinition('translator.data_collector')); |
| 47 | + } |
| 48 | + |
| 49 | + public function testProcessKeepsDataCollectorIfTranslatorImplementsTranslatorBagInterface() |
| 50 | + { |
| 51 | + $this->container->register('translator', 'Symfony\Component\Translation\Translator'); |
| 52 | + |
| 53 | + $this->dataCollectorTranslatorPass->process($this->container); |
| 54 | + |
| 55 | + $this->assertTrue($this->container->hasDefinition('data_collector.translation')); |
| 56 | + } |
| 57 | + |
| 58 | + public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface() |
| 59 | + { |
| 60 | + $this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag'); |
| 61 | + |
| 62 | + $this->dataCollectorTranslatorPass->process($this->container); |
| 63 | + |
| 64 | + $this->assertFalse($this->container->hasDefinition('translator.data_collector')); |
| 65 | + } |
| 66 | + |
| 67 | + public function testProcessRemovesDataCollectorIfTranslatorDoesNotImplementTranslatorBagInterface() |
| 68 | + { |
| 69 | + $this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag'); |
| 70 | + |
| 71 | + $this->dataCollectorTranslatorPass->process($this->container); |
| 72 | + |
| 73 | + $this->assertFalse($this->container->hasDefinition('data_collector.translation')); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +class TranslatorWithTranslatorBag implements TranslatorInterface |
| 78 | +{ |
| 79 | + public function trans($id, array $parameters = array(), $domain = null, $locale = null) |
| 80 | + { |
| 81 | + } |
| 82 | + |
| 83 | + public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) |
| 84 | + { |
| 85 | + } |
| 86 | + |
| 87 | + public function setLocale($locale) |
| 88 | + { |
| 89 | + } |
| 90 | + |
| 91 | + public function getLocale() |
| 92 | + { |
| 93 | + } |
| 94 | +} |
0 commit comments