Completed
Push — 2.x-dev-kit ( 6f250c )
by
unknown
02:44
created

ConfigurationTest::testApcDefaultTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
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->assertEquals($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->assertEquals($expected, $config['caches']['apc']['timeout']);
71
    }
72
73
    /**
74
     * Processes an array of configurations and returns a compiled version.
75
     *
76
     * @param array $configs An array of raw configurations
77
     *
78
     * @return array A normalized array
79
     */
80
    protected function process(array $configs)
81
    {
82
        $processor = new Processor();
83
84
        return $processor->processConfiguration(new Configuration(), $configs);
85
    }
86
}
87