ConfigurationTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 25
c 2
b 0
f 0
dl 0
loc 77
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvalidSiteUrl() 0 11 1
A testProcessSimpleCase() 0 19 1
A testInvalidRedirectCode() 0 11 1
A testInvalidRedirect() 0 10 1
A process() 0 5 1
1
<?php
2
3
namespace Palmtree\CanonicalUrlBundle\Tests\DependencyInjection;
4
5
use Palmtree\CanonicalUrlBundle\DependencyInjection\Configuration;
6
use Palmtree\CanonicalUrlBundle\Tests\AbstractTest;
7
use Symfony\Component\Config\Definition\Processor;
8
9
class ConfigurationTest extends AbstractTest
10
{
11
    /**
12
     * Some basic tests to make sure the configuration is correctly processed in
13
     * the standard case.
14
     */
15
    public function testProcessSimpleCase()
16
    {
17
        $configs = [
18
            [
19
                'site_url'       => 'https://example.org',
20
                'redirect'       => true,
21
                'redirect_code'  => 302,
22
                'trailing_slash' => true,
23
            ],
24
            [
25
                'trailing_slash' => false,
26
            ],
27
        ];
28
29
        $config = $this->process($configs);
30
31
        $this->assertArrayHasKey('site_url', $config);
32
        $this->assertTrue($config['redirect']);
33
        $this->assertFalse($config['trailing_slash']);
34
    }
35
36
    public function testInvalidSiteUrl()
37
    {
38
        $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
39
40
        $configs = [
41
            [
42
                'site_url' => false,
43
            ],
44
        ];
45
46
        $this->process($configs);
47
    }
48
49
    public function testInvalidRedirectCode()
50
    {
51
        $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
52
53
        $configs = [
54
            [
55
                'redirect_code' => 404,
56
            ],
57
        ];
58
59
        $this->process($configs);
60
    }
61
62
    public function testInvalidRedirect()
63
    {
64
        $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
65
        $configs = [
66
            [
67
                'redirect' => 9,
68
            ],
69
        ];
70
71
        $this->process($configs);
72
    }
73
74
    /**
75
     * Processes an array of configurations and returns a compiled version.
76
     *
77
     * @param array $configs An array of raw configurations
78
     *
79
     * @return array A normalized array
80
     */
81
    protected function process($configs)
82
    {
83
        $processor = new Processor();
84
85
        return $processor->processConfiguration(new Configuration(), $configs);
86
    }
87
}
88