1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Incenteev\TranslationCheckerBundle\Tests\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Incenteev\TranslationCheckerBundle\DependencyInjection\Compiler\ExtractorPass; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
10
|
|
|
|
11
|
|
|
class ExtractorPassTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testRegisterExtractors() |
14
|
|
|
{ |
15
|
|
|
$container = $this->createContainerBuilder(); |
16
|
|
|
|
17
|
|
|
$container->register('foo', 'stdClass') |
18
|
|
|
->addTag('incenteev_translation_checker.extractor'); |
19
|
|
|
|
20
|
|
|
$container->register('bar', 'stdClass') |
21
|
|
|
->addTag('incenteev_translation_checker.extractor'); |
22
|
|
|
|
23
|
|
|
$pass = new ExtractorPass(); |
24
|
|
|
|
25
|
|
|
$pass->process($container); |
26
|
|
|
|
27
|
|
|
$def = $container->getDefinition('incenteev_translation_checker.extractor.chain'); |
28
|
|
|
|
29
|
|
|
$this->assertEquals(array(new Reference('foo'), new Reference('bar')), $def->getArgument(0)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testRegisterNoExtractors() |
33
|
|
|
{ |
34
|
|
|
$container = $this->createContainerBuilder(); |
35
|
|
|
|
36
|
|
|
$pass = new ExtractorPass(); |
37
|
|
|
|
38
|
|
|
$pass->process($container); |
39
|
|
|
|
40
|
|
|
$def = $container->getDefinition('incenteev_translation_checker.extractor.chain'); |
41
|
|
|
|
42
|
|
|
$this->assertEquals(array(), $def->getArgument(0)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testRegisterSingleExtractor() |
46
|
|
|
{ |
47
|
|
|
$container = $this->createContainerBuilder(); |
48
|
|
|
|
49
|
|
|
$container->register('foo', 'stdClass') |
50
|
|
|
->addTag('incenteev_translation_checker.extractor'); |
51
|
|
|
|
52
|
|
|
$pass = new ExtractorPass(); |
53
|
|
|
|
54
|
|
|
$pass->process($container); |
55
|
|
|
|
56
|
|
|
$alias = $container->getAlias('incenteev_translation_checker.extractor'); |
57
|
|
|
|
58
|
|
|
$this->assertEquals('foo', (string) $alias); |
59
|
|
|
$this->assertFalse($alias->isPublic()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testRegisterSingleExtractorPreservesVisibility() |
63
|
|
|
{ |
64
|
|
|
$container = $this->createContainerBuilder(); |
65
|
|
|
|
66
|
|
|
$container->register('foo', 'stdClass') |
67
|
|
|
->addTag('incenteev_translation_checker.extractor'); |
68
|
|
|
$container->getAlias('incenteev_translation_checker.extractor')->setPublic(true); |
69
|
|
|
|
70
|
|
|
$pass = new ExtractorPass(); |
71
|
|
|
|
72
|
|
|
$pass->process($container); |
73
|
|
|
|
74
|
|
|
$alias = $container->getAlias('incenteev_translation_checker.extractor'); |
75
|
|
|
|
76
|
|
|
$this->assertEquals('foo', (string) $alias); |
77
|
|
|
$this->assertTrue($alias->isPublic()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function createContainerBuilder(): ContainerBuilder |
81
|
|
|
{ |
82
|
|
|
$container = new ContainerBuilder(); |
83
|
|
|
$container->register('incenteev_translation_checker.extractor.chain', 'Incenteev\TranslationCheckerBundle\Translator\Extractor\ChainExtractor') |
84
|
|
|
->addArgument(array()); |
85
|
|
|
$container->setAlias('incenteev_translation_checker.extractor', new Alias('incenteev_translation_checker.extractor.chain', false)); |
86
|
|
|
|
87
|
|
|
return $container; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|