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

assertParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Incenteev\TranslationCheckerBundle\Tests\DependencyInjection;
4
5
use Incenteev\TranslationCheckerBundle\DependencyInjection\IncenteevTranslationCheckerExtension;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
class IncenteevTranslationCheckerExtensionTest extends TestCase
10
{
11
    /**
12
     * @var ContainerBuilder
13
     */
14
    private $containerBuilder;
15
16
    protected function setUp()
17
    {
18
        $this->containerBuilder = new ContainerBuilder();
19
        $this->containerBuilder->setParameter('kernel.bundles', array(
20
            'IncenteevTranslationCheckerBundle' => 'Incenteev\TranslationCheckerBundle\IncenteevTranslationCheckerBundle',
21
            'FrameworkBundle' => 'Symfony\Bundle\FrameworkBundle\FrameworkBundle',
22
        ));
23
    }
24
25
    public function testDefaultPaths()
26
    {
27
        $extension = new IncenteevTranslationCheckerExtension();
28
29
        $extension->load(array(), $this->containerBuilder);
30
31
        $this->assertParameter(array('%kernel.root_dir%/Resources/views'), 'incenteev_translation_checker.extractor.symfony.paths');
32
        $this->assertFalse($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js'));
33
    }
34
35
    public function testBundlePaths()
36
    {
37
        $extension = new IncenteevTranslationCheckerExtension();
38
39
        $config = array('extraction' => array('bundles' => array('IncenteevTranslationCheckerBundle')));
40
41
        $extension->load(array($config), $this->containerBuilder);
42
43
        $expectedPaths = array(
44
            dirname(dirname(__DIR__)).'/src/Resources/views',
45
            '%kernel.root_dir%/Resources/IncenteevTranslationCheckerBundle/views',
46
            '%kernel.root_dir%/Resources/views',
47
        );
48
49
        $this->assertParameter($expectedPaths, 'incenteev_translation_checker.extractor.symfony.paths');
50
    }
51
52
    /**
53
     * @expectedException \InvalidArgumentException
54
     * @expectedExceptionMessage The bundle TwigBundle is not registered in the kernel.
55
     */
56
    public function testNotRegisteredBundle()
57
    {
58
        $extension = new IncenteevTranslationCheckerExtension();
59
60
        $config = array('extraction' => array('bundles' => array('TwigBundle')));
61
62
        $extension->load(array($config), $this->containerBuilder);
63
    }
64
65 View Code Duplication
    public function testJsExtractionPaths()
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...
66
    {
67
        $extension = new IncenteevTranslationCheckerExtension();
68
69
        $config = array('extraction' => array('js' => array('paths' => array('%kernel.project_dir%/web/js'))));
70
71
        $extension->load(array($config), $this->containerBuilder);
72
73
        $this->assertTrue($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js'));
74
75
        $def = $this->containerBuilder->getDefinition('incenteev_translation_checker.extractor.js');
76
77
        $this->assertEquals(array('%kernel.project_dir%/web/js'), $def->getArgument(0));
78
        $this->assertEquals('messages', $def->getArgument(1));
79
    }
80
81 View Code Duplication
    public function testJsExtractionDomain()
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...
82
    {
83
        $extension = new IncenteevTranslationCheckerExtension();
84
85
        $config = array('extraction' => array('js' => array('paths' => array('%kernel.project_dir%/web/js'), 'default_domain' => 'js_messages')));
86
87
        $extension->load(array($config), $this->containerBuilder);
88
89
        $this->assertTrue($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js'));
90
91
        $def = $this->containerBuilder->getDefinition('incenteev_translation_checker.extractor.js');
92
93
        $this->assertEquals(array('%kernel.project_dir%/web/js'), $def->getArgument(0));
94
        $this->assertEquals('js_messages', $def->getArgument(1));
95
    }
96
97
    /**
98
     * @param mixed  $value
99
     * @param string $key
100
     */
101
    private function assertParameter($value, $key)
102
    {
103
        $this->assertEquals($value, $this->containerBuilder->getParameter($key), sprintf('%s parameter is correct', $key));
104
    }
105
}
106