Completed
Push — master ( 0a7932...aee286 )
by Maksim
13s
created

FileSystemLoaderFactoryTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 38.46 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 6
dl 35
loc 91
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCouldBeConstructedWithoutAnyArguments() 0 4 1
A testImplementsLoaderFactoryInterface() 0 6 1
A testReturnExpectedName() 0 6 1
A testCreateLoaderDefinitionOnCreate() 18 18 1
A testProcessCorrectlyOptionsOnAddConfiguration() 0 19 1
A testAddDefaultOptionsIfNotSetOnAddConfiguration() 17 17 1
A processConfigTree() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory\Loader;
4
5
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\Processor;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
10
/**
11
 * @covers Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory<extended>
12
 */
13
class FileSystemLoaderFactoryTest extends \Phpunit_Framework_TestCase
14
{
15
    public function testImplementsLoaderFactoryInterface()
16
    {
17
        $rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory');
18
19
        $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface'));
20
    }
21
22
    public function testCouldBeConstructedWithoutAnyArguments()
23
    {
24
        new FileSystemLoaderFactory();
25
    }
26
27
    public function testReturnExpectedName()
28
    {
29
        $loader = new FileSystemLoaderFactory();
30
31
        $this->assertEquals('filesystem', $loader->getName());
32
    }
33
34 View Code Duplication
    public function testCreateLoaderDefinitionOnCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $container = new ContainerBuilder();
37
38
        $loader = new FileSystemLoaderFactory();
39
40
        $loader->create($container, 'theLoaderName', array(
41
            'data_root' => 'theDataRoot',
42
        ));
43
44
        $this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.theloadername'));
45
46
        $loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.theloadername');
47
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $loaderDefinition);
48
        $this->assertEquals('liip_imagine.binary.loader.prototype.filesystem', $loaderDefinition->getParent());
49
50
        $this->assertEquals('theDataRoot', $loaderDefinition->getArgument(2));
51
    }
52
53
    public function testProcessCorrectlyOptionsOnAddConfiguration()
54
    {
55
        $expectedDataRoot = 'theDataRoot';
56
57
        $treeBuilder = new TreeBuilder();
58
        $rootNode = $treeBuilder->root('filesystem', 'array');
59
60
        $loader = new FileSystemLoaderFactory();
61
        $loader->addConfiguration($rootNode);
62
63
        $config = $this->processConfigTree($treeBuilder, array(
64
            'filesystem' => array(
65
                'data_root' => $expectedDataRoot,
66
            ),
67
        ));
68
69
        $this->assertArrayHasKey('data_root', $config);
70
        $this->assertEquals($expectedDataRoot, $config['data_root']);
71
    }
72
73 View Code Duplication
    public function testAddDefaultOptionsIfNotSetOnAddConfiguration()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $expectedDataRoot = '%kernel.root_dir%/../web';
76
77
        $treeBuilder = new TreeBuilder();
78
        $rootNode = $treeBuilder->root('filesystem', 'array');
79
80
        $loader = new FileSystemLoaderFactory();
81
        $loader->addConfiguration($rootNode);
82
83
        $config = $this->processConfigTree($treeBuilder, array(
84
            'filesystem' => array(),
85
        ));
86
87
        $this->assertArrayHasKey('data_root', $config);
88
        $this->assertEquals($expectedDataRoot, $config['data_root']);
89
    }
90
91
    /**
92
     * @param TreeBuilder $treeBuilder
93
     * @param array       $configs
94
     *
95
     * @return array
96
     */
97
    protected function processConfigTree(TreeBuilder $treeBuilder, array $configs)
98
    {
99
        $processor = new Processor();
100
101
        return $processor->process($treeBuilder->buildTree(), $configs);
102
    }
103
}
104