14d164d0ee3c6ddcc78a26fa957feff52d72d566
[yaffs-website] / vendor / symfony / translation / Tests / DependencyInjection / TranslationExtractorPassTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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\Component\Translation\Tests\DependencyInjection;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
18
19 class TranslationExtractorPassTest extends TestCase
20 {
21     public function testProcess()
22     {
23         $container = new ContainerBuilder();
24         $extractorDefinition = $container->register('translation.extractor');
25         $container->register('foo.id')
26             ->addTag('translation.extractor', array('alias' => 'bar.alias'));
27
28         $translationDumperPass = new TranslationExtractorPass();
29         $translationDumperPass->process($container);
30
31         $this->assertEquals(array(array('addExtractor', array('bar.alias', new Reference('foo.id')))), $extractorDefinition->getMethodCalls());
32     }
33
34     public function testProcessNoDefinitionFound()
35     {
36         $container = new ContainerBuilder();
37
38         $definitionsBefore = \count($container->getDefinitions());
39         $aliasesBefore = \count($container->getAliases());
40
41         $translationDumperPass = new TranslationExtractorPass();
42         $translationDumperPass->process($container);
43
44         // the container is untouched (i.e. no new definitions or aliases)
45         $this->assertCount($definitionsBefore, $container->getDefinitions());
46         $this->assertCount($aliasesBefore, $container->getAliases());
47     }
48
49     /**
50      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
51      * @expectedExceptionMessage The alias for the tag "translation.extractor" of service "foo.id" must be set.
52      */
53     public function testProcessMissingAlias()
54     {
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());
60
61         $definition->expects($this->never())->method('addMethodCall');
62
63         $translationDumperPass = new TranslationExtractorPass();
64         $translationDumperPass->process($container);
65     }
66 }