Completed
Push — master ( e207d9...c74d35 )
by Eric
09:33
created

TemplatingCompilerPassTest::createContainerBuilderMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Ivory Form Extra 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 Ivory\FormExtraBundle\Tests\DependencyInjection\Compiler;
13
14
use Ivory\FormExtraBundle\DependencyInjection\Compiler\TemplatingCompilerPass;
15
16
/**
17
 * Templating compiler pass test.
18
 *
19
 * @author GeLo <[email protected]>
20
 */
21
class TemplatingCompilerPassTest extends \PHPUnit_Framework_TestCase
22
{
23
    /** @var \Ivory\FormExtraBundle\DependencyInjection\Compiler\TemplatingCompilerPass */
24
    private $compilerPass;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function setUp()
30
    {
31
        $this->compilerPass = new TemplatingCompilerPass();
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function tearDown()
38
    {
39
        unset($this->compilerPass);
40
    }
41
42
    public function testPhpTemplating()
43
    {
44
        $containerBuilder = $this->createContainerBuilderMock();
45
        $containerBuilder
46
            ->expects($this->exactly(2))
47
            ->method('hasDefinition')
48
            ->will($this->returnValueMap(array(
49
                array('templating.engine.php', false),
50
                array('twig', true),
51
            )));
52
53
        $containerBuilder
54
            ->expects($this->once())
55
            ->method('removeDefinition')
56
            ->with($this->identicalTo('ivory_form_extra.templating.helper'));
57
58
        $this->compilerPass->process($containerBuilder);
59
    }
60
61
    public function testTwigTemplating()
62
    {
63
        $containerBuilder = $this->createContainerBuilderMock();
64
        $containerBuilder
65
            ->expects($this->exactly(2))
66
            ->method('hasDefinition')
67
            ->will($this->returnValueMap(array(
68
                array('templating.engine.php', true),
69
                array('twig', false),
70
            )));
71
72
        $containerBuilder
73
            ->expects($this->once())
74
            ->method('removeDefinition')
75
            ->with($this->identicalTo('ivory_form_extra.twig.extension'));
76
77
        $this->compilerPass->process($containerBuilder);
78
    }
79
80
    /**
81
     * Creates a container builder mock.
82
     *
83
     * @return \Symfony\Component\DependencyInjection\ContainerBuilder|\PHPUnit_Framework_MockObject_MockObject The container builder mock.
84
     */
85
    private function createContainerBuilderMock()
86
    {
87
        return $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
88
            ->disableOriginalConstructor()
89
            ->setMethods(array('hasDefinition', 'removeDefinition'))
90
            ->getMock();
91
    }
92
}
93