Completed
Pull Request — master (#47)
by Maximilian
62:08 queued 57s
created

TemplatingCompilerPassTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 56.25 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 36
loc 64
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\CKEditorBundle\Tests\DependencyInjection\Compiler;
13
14
use FOS\CKEditorBundle\DependencyInjection\Compiler\TemplatingCompilerPass;
15
use FOS\CKEditorBundle\Tests\AbstractTestCase;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
class TemplatingCompilerPassTest extends AbstractTestCase
22
{
23
    /**
24
     * @var TemplatingCompilerPass
25
     */
26
    private $compilerPass;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function setUp()
32
    {
33
        $this->compilerPass = new TemplatingCompilerPass();
34
    }
35
36
    public function testPhpTemplating()
37
    {
38
        $containerBuilder = $this->createContainerBuilderMock();
39
        $containerBuilder
40
            ->expects($this->exactly(2))
41
            ->method('hasDefinition')
42
            ->will($this->returnValueMap([
43
                ['templating.engine.php', false],
44
                ['twig', true],
45
            ]));
46
47
        $containerBuilder
48
            ->expects($this->once())
49
            ->method('removeDefinition')
50
            ->with($this->identicalTo('fos_ck_editor.templating.helper'));
51
52
        $this->compilerPass->process($containerBuilder);
53
    }
54
55
    public function testTwigTemplating()
56
    {
57
        $containerBuilder = $this->createContainerBuilderMock();
58
        $containerBuilder
59
            ->expects($this->exactly(2))
60
            ->method('hasDefinition')
61
            ->will($this->returnValueMap([
62
                ['templating.engine.php', true],
63
                ['twig', false],
64
            ]));
65
66
        $containerBuilder
67
            ->expects($this->once())
68
            ->method('removeDefinition')
69
            ->with($this->identicalTo('fos_ck_editor.twig_extension'));
70
71
        $this->compilerPass->process($containerBuilder);
72
    }
73
74
    /**
75
     * @return ContainerBuilder|\PHPUnit_Framework_MockObject_MockObject
76
     */
77
    private function createContainerBuilderMock()
78
    {
79
        return $this->getMockBuilder(ContainerBuilder::class)
80
            ->disableOriginalConstructor()
81
            ->setMethods(['hasDefinition', 'removeDefinition'])
82
            ->getMock();
83
    }
84
}
85