Completed
Pull Request — 2.x (#115)
by Rémi
06:46
created

ConfigurationTest::testSymfonyDefaultTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
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\CacheBundle\Tests\DependencyInjection\Configuration;
13
14
use Sonata\CacheBundle\DependencyInjection\Configuration;
15
use Symfony\Component\Config\Definition\Processor;
16
17
/**
18
 * Tests the Configuration class.
19
 */
20
class ConfigurationTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * Asserts APC has default timeout values.
24
     */
25
    public function testApcDefaultTimeout()
26
    {
27
        $expected = array(
28
            'RCV' => array(),
29
            'SND' => array(),
30
        );
31
32
        $configs = array(array(
33
            'caches' => array(
34
                'apc' => array(
35
                    'token' => '',
36
                    'prefix' => '',
37
                ),
38
            ),
39
        ));
40
41
        $config = $this->process($configs);
42
43
        $this->assertArrayHasKey('timeout', $config['caches']['apc']);
44
        $this->assertSame($expected, $config['caches']['apc']['timeout']);
45
    }
46
47
    /**
48
     * Asserts APC timeout has custom values.
49
     */
50
    public function testApcCustomTimeout()
51
    {
52
        $expected = array(
53
            'RCV' => array('sec' => 10, 'usec' => 0),
54
            'SND' => array('sec' => 18, 'usec' => 12),
55
        );
56
57
        $configs = array(array(
58
            'caches' => array(
59
                'apc' => array(
60
                    'token' => '',
61
                    'prefix' => '',
62
                    'timeout' => $expected,
63
                ),
64
            ),
65
        ));
66
67
        $config = $this->process($configs);
68
69
        $this->assertArrayHasKey('timeout', $config['caches']['apc']);
70
        $this->assertSame($expected, $config['caches']['apc']['timeout']);
71
    }
72
73
    /**
74
     * Asserts Symfony has default timeout values.
75
     */
76
    public function testSymfonyDefaultTimeout()
77
    {
78
        $expected = array(
79
            'RCV' => array('sec' => 2, 'usec' => 0),
80
            'SND' => array('sec' => 2, 'usec' => 0),
81
        );
82
83
        $configs = array(array(
84
            'caches' => array(
85
                'symfony' => array(
86
                    'token' => '',
87
                    'types' => array('all'),
88
                ),
89
            ),
90
        ));
91
92
        $config = $this->process($configs);
93
94
        $this->assertArrayHasKey('timeout', $config['caches']['symfony']);
95
        $this->assertSame($expected, $config['caches']['symfony']['timeout']);
96
    }
97
98
    /**
99
     * Asserts Symfony timeout has custom values.
100
     */
101
    public function testSymfonyCustomTimeout()
102
    {
103
        $expected = array(
104
            'RCV' => array('sec' => 10, 'usec' => 0),
105
            'SND' => array('sec' => 18, 'usec' => 12),
106
        );
107
108
        $configs = array(array(
109
            'caches' => array(
110
                'symfony' => array(
111
                    'token' => '',
112
                    'types' => array('all'),
113
                    'timeout' => $expected,
114
                ),
115
            ),
116
        ));
117
118
        $config = $this->process($configs);
119
120
        $this->assertArrayHasKey('timeout', $config['caches']['symfony']);
121
        $this->assertSame($expected, $config['caches']['symfony']['timeout']);
122
    }
123
124
    /**
125
     * Processes an array of configurations and returns a compiled version.
126
     *
127
     * @param array $configs An array of raw configurations
128
     *
129
     * @return array A normalized array
130
     */
131
    protected function process(array $configs)
132
    {
133
        $processor = new Processor();
134
135
        return $processor->processConfiguration(new Configuration(), $configs);
136
    }
137
}
138