4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Tests\DependencyInjection;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
19 class TranslationExtractorPassTest extends TestCase
21 public function testProcess()
23 $container = new ContainerBuilder();
24 $extractorDefinition = $container->register('translation.extractor');
25 $container->register('foo.id')
26 ->addTag('translation.extractor', array('alias' => 'bar.alias'));
28 $translationDumperPass = new TranslationExtractorPass();
29 $translationDumperPass->process($container);
31 $this->assertEquals(array(array('addExtractor', array('bar.alias', new Reference('foo.id')))), $extractorDefinition->getMethodCalls());
34 public function testProcessNoDefinitionFound()
36 $container = new ContainerBuilder();
38 $definitionsBefore = \count($container->getDefinitions());
39 $aliasesBefore = \count($container->getAliases());
41 $translationDumperPass = new TranslationExtractorPass();
42 $translationDumperPass->process($container);
44 // the container is untouched (i.e. no new definitions or aliases)
45 $this->assertCount($definitionsBefore, $container->getDefinitions());
46 $this->assertCount($aliasesBefore, $container->getAliases());
50 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
51 * @expectedExceptionMessage The alias for the tag "translation.extractor" of service "foo.id" must be set.
53 public function testProcessMissingAlias()
55 $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->disableOriginalConstructor()->getMock();
56 $container = new ContainerBuilder();
57 $container->register('translation.extractor');
58 $container->register('foo.id')
59 ->addTag('translation.extractor', array());
61 $definition->expects($this->never())->method('addMethodCall');
63 $translationDumperPass = new TranslationExtractorPass();
64 $translationDumperPass->process($container);