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

testAddDefaultOptionsIfNotSetOnAddConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 17
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
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