Passed
Pull Request — master (#20)
by Christophe
03:13
created

ExtractorPassTest::createContainerBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 9.4285
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 View Code Duplication
    public function testRegisterSingleExtractor()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    public function testRegisterSingleExtractorPreservesVisibility()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
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