ConfigurationTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 101
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testApcDefaultTimeout() 0 22 1
A testApcCustomTimeout() 0 22 1
A testSymfonyDefaultTimeout() 0 22 1
A testSymfonyCustomTimeout() 0 22 1
A process() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\CacheBundle\Tests\DependencyInjection\Configuration;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\CacheBundle\DependencyInjection\Configuration;
18
use Symfony\Component\Config\Definition\Processor;
19
20
class ConfigurationTest extends TestCase
21
{
22
    public function testApcDefaultTimeout(): void
23
    {
24
        $configs = [[
25
            'caches' => [
26
                'apc' => [
27
                    'token' => '',
28
                    'prefix' => '',
29
                ],
30
            ],
31
        ]];
32
33
        $config = $this->process($configs);
34
35
        $this->assertArrayHasKey('timeout', $config['caches']['apc']);
36
        $this->assertSame(
37
            [
38
                'RCV' => [],
39
                'SND' => [],
40
            ],
41
            $config['caches']['apc']['timeout']
42
        );
43
    }
44
45
    public function testApcCustomTimeout(): void
46
    {
47
        $expected = [
48
            'RCV' => ['sec' => 10, 'usec' => 0],
49
            'SND' => ['sec' => 18, 'usec' => 12],
50
        ];
51
52
        $configs = [[
53
            'caches' => [
54
                'apc' => [
55
                    'token' => '',
56
                    'prefix' => '',
57
                    'timeout' => $expected,
58
                ],
59
            ],
60
        ]];
61
62
        $config = $this->process($configs);
63
64
        $this->assertArrayHasKey('timeout', $config['caches']['apc']);
65
        $this->assertSame($expected, $config['caches']['apc']['timeout']);
66
    }
67
68
    public function testSymfonyDefaultTimeout(): void
69
    {
70
        $configs = [[
71
            'caches' => [
72
                'symfony' => [
73
                    'token' => '',
74
                    'types' => ['all'],
75
                ],
76
            ],
77
        ]];
78
79
        $config = $this->process($configs);
80
81
        $this->assertArrayHasKey('timeout', $config['caches']['symfony']);
82
        $this->assertSame(
83
            [
84
                'RCV' => ['sec' => 2, 'usec' => 0],
85
                'SND' => ['sec' => 2, 'usec' => 0],
86
            ],
87
            $config['caches']['symfony']['timeout']
88
        );
89
    }
90
91
    public function testSymfonyCustomTimeout(): void
92
    {
93
        $expected = [
94
            'RCV' => ['sec' => 10, 'usec' => 0],
95
            'SND' => ['sec' => 18, 'usec' => 12],
96
        ];
97
98
        $configs = [[
99
            'caches' => [
100
                'symfony' => [
101
                    'token' => '',
102
                    'types' => ['all'],
103
                    'timeout' => $expected,
104
                ],
105
            ],
106
        ]];
107
108
        $config = $this->process($configs);
109
110
        $this->assertArrayHasKey('timeout', $config['caches']['symfony']);
111
        $this->assertSame($expected, $config['caches']['symfony']['timeout']);
112
    }
113
114
    protected function process(array $configs): array
115
    {
116
        $processor = new Processor();
117
118
        return $processor->processConfiguration(new Configuration(), $configs);
119
    }
120
}
121