Completed
Pull Request — master (#47)
by Maximilian
392:42 queued 327:39
created

ResourceCompilerPassTest::testPhpResource()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 27
Ratio 100 %

Importance

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