testLoadMetadataCacheRemoveAlias()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the OpensoftEplBundle package.
4
 *
5
 * Copyright (c) 2011 Farheap Solutions (http://www.farheap.com)
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Opensoft\Bundle\SimpleSerializerBundle\Tests\DependencyInjection;
12
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Definition;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
use Opensoft\Bundle\SimpleSerializerBundle\DependencyInjection\OpensoftSimpleSerializerExtension;
18
19
/**
20
 * OpensoftEplExtension test.
21
 *
22
 * @author Dmitry Petrov <[email protected]><fightmaster>
23
 */
24
class OpensoftSimpleSerializerExtensionTest extends \PHPUnit_Framework_TestCase
25
{
26
    /**
27
     * @var ContainerBuilder
28
     */
29
    private $container;
30
    private $extension;
31
32
    public function testGetConfiguration()
33
    {
34
        $result = $this->extension->getConfiguration(array(), $this->container);
35
        $this->assertInstanceOf('Opensoft\Bundle\SimpleSerializerBundle\DependencyInjection\Configuration', $result);
36
    }
37
38
    public function testLoadMetadataCache()
39
    {
40
        $this->extension->load(
41
            array(
42
                'opensoft_simple_serializer' => array(
43
                    'metadata' => array(
44
                        'cache' => 'file',
45
                        'file_cache' => array('dir' => __DIR__ . '/../cache'),
46
                        'directories' => array (
47
                            array ('path' => '/tmp/simple-serializer', 'namespace_prefix' => '/tmp'),
48
                            array ('path' => '@OpensoftSimpleSerializerBundle/Resources/config', 'namespace_prefix' => 'test')
49
                        )
50
                    )
51
                ),
52
            ), $this->container);
53
        $definition = $this->container->getDefinition('opensoft_simple_serializer.metadata.cache.file');
54
        $definitionFileLocator = $this->container->getDefinition('opensoft_simple_serializer.metadata.driver.file_locator');
55
        $alias = $this->container->getAlias('opensoft_simple_serializer.metadata.cache');
56
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\Alias', $alias);
57
        $this->assertEquals(__DIR__ . '/../cache', $definition->getArgument(0));
58
        $dirs = $definitionFileLocator->getArgument(0);
59
        $this->assertCount(3, $dirs);
60
        $this->assertArrayHasKey('test', $dirs);
61
        $this->assertArrayHasKey('/tmp', $dirs);
62
        $this->assertArrayHasKey('Opensoft\Bundle\SimpleSerializerBundle', $dirs);
63
        $this->assertStringEndsWith('OpensoftSimpleSerializerBundle/Resources/config/simple-serializer', $dirs['Opensoft\Bundle\SimpleSerializerBundle']);
64
        $this->assertEquals('/tmp/simple-serializer', $dirs['/tmp']);
65
        $this->assertStringEndsWith('OpensoftSimpleSerializerBundle/Resources/config', $dirs['test']);
66
    }
67
68
    /**
69
     * @expectedException Opensoft\Bundle\SimpleSerializerBundle\Exception\RuntimeException
70
     */
71
    public function testLoadMetadataCacheRuntimeExceptionParseDir()
72
    {
73
        $this->extension->load(
74
            array(
75
                'opensoft_simple_serializer' => array(
76
                    'metadata' => array(
77
                        'cache' => 'file',
78
                        'file_cache' => array('dir' => '/tmp'),
79
                        'directories' => array (
80
                            array ('path' => '@Opensoft/Resource/config', 'namespace_prefix' => 'test')
81
                        )
82
                    )
83
                ),
84
            ), $this->container);
85
    }
86
87
    /**
88
     * @expectedException Opensoft\Bundle\SimpleSerializerBundle\Exception\RuntimeException
89
     */
90
    public function testLoadMetadataCacheRuntimeException()
91
    {
92
        $this->extension->load(
93
            array(
94
                'opensoft_simple_serializer' => array(
95
                    'metadata' => array(
96
                        'cache' => 'file',
97
                        'file_cache' => array('dir' => '/tmpRes')
98
                    )
99
                ),
100
            ), $this->container);
101
    }
102
103
    public function testLoadMetadataCacheRemoveAlias()
104
    {
105
        $this->extension->load(
106
            array(
107
                'opensoft_simple_serializer' => array(
108
                    'metadata' => array(
109
                        'cache' => 'none',
110
                        'file_cache' => array('dir' => '/tmp')
111
                    )
112
                ),
113
            ), $this->container);
114
        $this->assertFalse($this->container->hasAlias('opensoft_simple_serializer.metadata.cache'));
115
116
    }
117
118
    public function testLoadMetadataCacheSetAlias()
119
    {
120
        $this->extension->load(
121
            array(
122
                'opensoft_simple_serializer' => array(
123
                    'metadata' => array(
124
                        'cache' => 'memcache',
125
                        'file_cache' => array('dir' => '/tmp')
126
                    )
127
                ),
128
            ), $this->container);
129
        $this->assertFalse($this->container->getAlias('opensoft_simple_serializer.metadata.cache.file')->isPublic());
130
131
    }
132
133
    protected function setUp()
134
    {
135
        $this->container = new ContainerBuilder();
136
        $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
137
        $kernel
138
            ->expects($this->any())
139
            ->method('getBundles')
140
            ->will($this->returnValue(array('OpensoftSimpleSerializerBundle' => 'Opensoft\Bundle\SimpleSerializerBundle\OpensoftSimpleSerializerBundle')
141
        ))
142
        ;
143
        $kernel
144
            ->expects($this->any())
145
            ->method('isDebug')
146
            ->will($this->returnValue(false))
147
        ;
148
        $this->extension = new OpensoftSimpleSerializerExtension($kernel);
149
        $this->container->setParameter('kernel.bundles', $kernel->getBundles());
150
    }
151
152
    protected function tearDown()
153
    {
154
        unset($this->container, $this->extension);
155
    }
156
}
157