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

ResourceCompilerPassTest::testTwigResource()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 23

Duplication

Lines 31
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 31
loc 31
rs 8.8571
cc 1
eloc 23
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\ResourceCompilerPass;
15
16
/**
17
 * Resource compiler pass test.
18
 *
19
 * @author GeLo <[email protected]>
20
 */
21
class ResourceCompilerPassTest extends \PHPUnit_Framework_TestCase
22
{
23
    /** @var \Ivory\FormExtraBundle\DependencyInjection\Compiler\ResourceCompilerPass */
24
    private $compilerPass;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function setUp()
30
    {
31
        $this->compilerPass = new ResourceCompilerPass();
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function tearDown()
38
    {
39
        unset($this->compilerPass);
40
    }
41
42
    public function testTwigResource()
43
    {
44
        $containerBuilder = $this->createContainerBuilderMock();
45
        $containerBuilder
46
            ->expects($this->exactly(2))
47
            ->method('hasParameter')
48
            ->will($this->returnValueMap(array(
49
                array('templating.helper.form.resources', false),
50
                array($parameter = 'twig.form.resources', true),
51
            )));
52
53
        $containerBuilder
54
            ->expects($this->once())
55
            ->method('getParameter')
56
            ->with($this->identicalTo($parameter))
57
            ->will($this->returnValue(array($template = 'layout.html.twig')));
58
59
        $containerBuilder
60
            ->expects($this->once())
61
            ->method('setParameter')
62
            ->with(
63
                $this->identicalTo($parameter),
64
                $this->identicalTo(array(
65
                    'IvoryFormExtraBundle:Form:javascript.html.twig',
66
                    'IvoryFormExtraBundle:Form:stylesheet.html.twig',
67
                    $template,
68
                ))
69
            );
70
71
        $this->compilerPass->process($containerBuilder);
72
    }
73
74
    public function testPhpResource()
75
    {
76
        $containerBuilder = $this->createContainerBuilderMock();
77
        $containerBuilder
78
            ->expects($this->exactly(2))
79
            ->method('hasParameter')
80
            ->will($this->returnValueMap(array(
81
                array($parameter = 'templating.helper.form.resources', true),
82
                array('twig.form.resources', false),
83
            )));
84
85
        $containerBuilder
86
            ->expects($this->once())
87
            ->method('getParameter')
88
            ->with($this->identicalTo($parameter))
89
            ->will($this->returnValue(array($template = 'layout.html.php')));
90
91
        $containerBuilder
92
            ->expects($this->once())
93
            ->method('setParameter')
94
            ->with(
95
                $this->identicalTo($parameter),
96
                $this->identicalTo(array('IvoryFormExtraBundle:Form', $template))
97
            );
98
99
        $this->compilerPass->process($containerBuilder);
100
    }
101
102
    /**
103
     * Creates a container builder mock.
104
     *
105
     * @return \Symfony\Component\DependencyInjection\ContainerBuilder|\PHPUnit_Framework_MockObject_MockObject
106
     */
107
    private function createContainerBuilderMock()
108
    {
109
        return $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
110
            ->disableOriginalConstructor()
111
            ->setMethods(array('hasParameter', 'getParameter', 'setParameter'))
112
            ->getMock();
113
    }
114
}
115