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); |
|
|
|
|
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); |
|
|
|
|
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); |
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.