1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Velikonja\LabbyBundle\Test\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Processor; |
6
|
|
|
use Symfony\Component\Yaml\Yaml; |
7
|
|
|
use Velikonja\LabbyBundle\DependencyInjection\Configuration; |
8
|
|
|
|
9
|
|
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Tests example configuration. Will throw exception if does not validate. |
13
|
|
|
* |
14
|
|
|
* @param string $path |
15
|
|
|
* |
16
|
|
|
* @dataProvider getValidConfigurationsPaths |
17
|
|
|
*/ |
18
|
|
|
public function testValidConfigurations($path) |
19
|
|
|
{ |
20
|
|
|
$config = Yaml::parse(file_get_contents($path)); |
21
|
|
|
$processor = new Processor(); |
22
|
|
|
$configuration = new Configuration(); |
23
|
|
|
|
24
|
|
|
$processor->processConfiguration( |
25
|
|
|
$configuration, |
26
|
|
|
$config |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
$this->assertTrue(true); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $path |
34
|
|
|
* |
35
|
|
|
* @dataProvider getInvalidConfigurationsPaths |
36
|
|
|
* |
37
|
|
|
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
38
|
|
|
*/ |
39
|
|
|
public function testInvalidConfigurations($path) |
40
|
|
|
{ |
41
|
|
|
$config = Yaml::parse(file_get_contents($path)); |
42
|
|
|
$processor = new Processor(); |
43
|
|
|
$configuration = new Configuration(); |
44
|
|
|
|
45
|
|
|
$processor->processConfiguration( |
46
|
|
|
$configuration, |
47
|
|
|
$config |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function getValidConfigurationsPaths() |
55
|
|
|
{ |
56
|
|
|
return $this->getConfigurationsPaths('valid'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getInvalidConfigurationsPaths() |
63
|
|
|
{ |
64
|
|
|
return $this->getConfigurationsPaths('invalid'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $type |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function getConfigurationsPaths($type) |
73
|
|
|
{ |
74
|
|
|
$files = glob( |
75
|
|
|
$this->getConfigsDir() . sprintf('/%s/*.yml', $type) |
76
|
|
|
); |
77
|
|
|
$args = array(); |
78
|
|
|
|
79
|
|
|
foreach ($files as $file) { |
80
|
|
|
$args[] = array($file); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $args; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
* |
89
|
|
|
*/ |
90
|
|
|
private function getConfigsDir() |
91
|
|
|
{ |
92
|
|
|
$path = realpath( |
93
|
|
|
__DIR__ . sprintf('/../fixtures/configs') |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
if (! $path) { |
97
|
|
|
throw new \LogicException('Config dir does not exists.'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $path; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|