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

testDefaultBehavior()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 54
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
dl 0
loc 54
rs 9.6716
c 2
b 1
f 1
cc 3
eloc 32
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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