Completed
Push — 2.x ( 359f6e )
by Sullivan
14:45
created

AddTemplatesCompilerPassTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
c 2
b 1
f 1
lcom 1
cbo 3
dl 0
loc 57
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testDefaultBehavior() 0 54 3
1
<?php
2
3
/*
4
 * This file is part of the Sonata project.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrineORMAdminBundle\Tests\DependencyInjection\Compiler;
13
14
use Sonata\DoctrineORMAdminBundle\DependencyInjection\Compiler\AddTemplatesCompilerPass;
15
use Symfony\Component\DependencyInjection\Definition;
16
17
class AddTemplatesCompilerPassTest extends \PHPUnit_Framework_TestCase
18
{
19
    public function testDefaultBehavior()
20
    {
21
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
22
23
        $container
24
            ->expects($this->any())
25
            ->method('getParameter')
26
            ->will($this->returnCallback(function($value) {
27
                if ($value == 'sonata.admin.configuration.admin_services') {
28
                    return array(
29
                        'my.admin' => array(
30
                            'templates' => array(
31
                                'form'   => array('myform.twig.html'),
32
                                'filter' => array('myfilter.twig.html')
33
                            )
34
                        )
35
                    );
36
                }
37
38
                if ($value == 'sonata_doctrine_orm_admin.templates') {
39
                    return array(
40
                        'form' => array('default_form.twig.html'),
41
                        'filter' => array('default_filter.twig.html'),
42
                    );
43
                }
44
            }))
45
        ;
46
47
        $container
48
            ->expects($this->any())
49
            ->method('findTaggedServiceIds')
50
            ->will($this->returnValue(array('my.admin' => array(array('manager_type' => 'orm')))))
51
        ;
52
53
        $definition = new Definition(null);
54
55
        $container
56
            ->expects($this->any())
57
            ->method('getDefinition')
58
            ->will($this->returnValue($definition))
59
        ;
60
61
        $definition->addMethodCall('setFilterTheme', array(array('custom_call.twig.html')));
62
63
        $compilerPass = new AddTemplatesCompilerPass();
64
        $compilerPass->process($container);
65
66
        $expected = array(
67
            array('setFilterTheme', array(array('custom_call.twig.html', 'myfilter.twig.html',))),
68
            array('setFormTheme', array(array('default_form.twig.html', 'myform.twig.html',))),
69
        );
70
71
        $this->assertEquals($expected, $definition->getMethodCalls());
72
    }
73
}
74