Completed
Push — master ( f7b33a...213343 )
by Andy
03:36
created

ConfigurationTest::testInvalidSiteUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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 = array(
18
            array(
19
                'site_url' => 'https://example.org',
20
                'redirect' => true,
21
                'redirect_code' => 302,
22
                'trailing_slash' => true,
23
            ),
24
            array(
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
    /**
37
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
38
     */
39
    public function testInvalidSiteUrl()
40
    {
41
        $configs = array(
42
            array(
43
                'site_url' => false,
44
            )
45
        );
46
47
        $config = $this->process($configs);
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
48
    }
49
50
    /**
51
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
52
     */
53
    public function testInvalidRedirectCode()
54
    {
55
        $configs = array(
56
            array(
57
                'redirect_code' => 404,
58
            )
59
        );
60
61
        $config = $this->process($configs);
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
    }
63
64
    /**
65
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
66
     */
67
    public function testInvalidRedirect()
68
    {
69
        $configs = array(
70
            array(
71
                'redirect' => 9,
72
            )
73
        );
74
75
        $config = $this->process($configs);
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
76
    }
77
78
    /**
79
     * Processes an array of configurations and returns a compiled version.
80
     *
81
     * @param array $configs An array of raw configurations
82
     *
83
     * @return array A normalized array
84
     */
85
    protected function process($configs)
86
    {
87
        $processor = new Processor();
88
89
        return $processor->processConfiguration(new Configuration(), $configs);
90
    }
91
}
92