testValidConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace Wikibase\EntityStore\Config;
4
5
use Symfony\Component\Config\Definition\Processor;
6
7
/**
8
 * @covers Wikibase\EntityStore\Config\EntityStoreConfiguration
9
 *
10
 * @licence GPLv2+
11
 * @author Thomas Pellissier Tanon
12
 */
13
class EntityStoreConfigurationTest extends \PHPUnit_Framework_TestCase {
14
15
	/**
16
	 * @dataProvider validConfigurationProvider
17
	 */
18
	public function testValidConfiguration( array $initialConfig, array $processedConfig ) {
19
		$processor = new Processor();
20
		$configuration = new EntityStoreConfiguration();
21
22
		$this->assertEquals(
23
			$processedConfig,
24
			$processor->processConfiguration( $configuration, [ $initialConfig ] )
25
		);
26
	}
27
28
	public function validConfigurationProvider() {
29
		return [
30
			[
31
				[
32
					'backend' => 'api',
33
					'api' => [
34
						'url' => 'http://www.wikidata.org/w/api.php'
35
					]
36
				],
37
				[
38
					'backend' => 'api',
39
					'api' => [
40
						'url' => 'http://www.wikidata.org/w/api.php'
41
					],
42
					'options' => []
43
				]
44
			],
45
			[
46
				[
47
					'backend' => 'api',
48
					'api' => [
49
						'url' => 'http://www.wikidata.org/w/api.php',
50
						'wikidataquery-url' => 'http://wdq.wmflabs.org/api'
51
					]
52
				],
53
				[
54
					'backend' => 'api',
55
					'api' => [
56
						'url' => 'http://www.wikidata.org/w/api.php',
57
						'wikidataquery_url' => 'http://wdq.wmflabs.org/api'
58
					],
59
					'options' => []
60
				]
61
			],
62
			[
63
				[
64
					'backend' => 'mongodb',
65
					'mongodb' => [
66
						'server' => ''
67
					]
68
				],
69
				[
70
					'backend' => 'mongodb',
71
					'mongodb' => [
72
						'server' => '',
73
						'database' => 'wikibase'
74
					],
75
					'options' => []
76
				]
77
			],
78
			[
79
				[
80
					'backend' => 'api',
81
					'api' => [
82
						'url' => 'http://www.wikidata.org/w/api.php'
83
					],
84
					'cache' => [
85
						'memcached' => true,
86
						'array' => true
87
					]
88
				],
89
				[
90
					'backend' => 'api',
91
					'api' => [
92
						'url' => 'http://www.wikidata.org/w/api.php'
93
					],
94
					'cache' => [
95
						'lifetime' => 0,
96
						'memcached' => [
97
							'enabled' => true,
98
							'host' => 'localhost',
99
							'port' => 11211
100
						],
101
						'array' => [
102
							'enabled' => true
103
						]
104
					],
105
					'options' => []
106
				]
107
			],
108
			[
109
				[
110
					'backend' => 'api',
111
					'api' => [
112
						'url' => 'http://www.wikidata.org/w/api.php'
113
					],
114
					'cache' => [
115
						'lifetime' => 30000,
116
						'memcached' => false,
117
						'array' => false
118
					]
119
				],
120
				[
121
					'backend' => 'api',
122
					'api' => [
123
						'url' => 'http://www.wikidata.org/w/api.php'
124
					],
125
					'cache' => [
126
						'lifetime' => 30000,
127
						'memcached' => [
128
							'enabled' => false,
129
							'host' => 'localhost',
130
							'port' => 11211
131
						],
132
						'array' => [
133
							'enabled' => false
134
						]
135
					],
136
					'options' => []
137
				]
138
			],
139
			[
140
				[
141
					'backend' => 'api',
142
					'api' => [
143
						'url' => 'http://www.wikidata.org/w/api.php'
144
					],
145
					'options' => [
146
						'languages' => [ 'en', 'fr' ]
147
					]
148
				],
149
				[
150
					'backend' => 'api',
151
					'api' => [
152
						'url' => 'http://www.wikidata.org/w/api.php'
153
					],
154
					'options' => [
155
						'languages' => [ 'en', 'fr' ]
156
					]
157
				]
158
			],
159
		];
160
	}
161
162
	/**
163
	 * @dataProvider invalidConfigurationProvider
164
	 */
165
	public function testInvalidConfiguration( array $initialConfig ) {
166
		$processor = new Processor();
167
		$configuration = new EntityStoreConfiguration();
168
169
		$this->setExpectedException( 'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException' );
170
		$processor->processConfiguration( $configuration, [ $initialConfig ] );
171
	}
172
173
	public function invalidConfigurationProvider() {
174
		return [
175
			[
176
				[]
177
			],
178
			[
179
				[
180
					'backend' => 'foo'
181
				]
182
			],
183
			[
184
				[
185
					'backend' => 'api',
186
					'api' => []
187
				]
188
			],
189
			[
190
				[
191
					'backend' => 'api',
192
					'api' => [
193
						'url' => ''
194
					]
195
				]
196
			],
197
			[
198
				[
199
					'backend' => 'api',
200
					'api' => [
201
						'url' => 'http://www.wikidata.org/w/api.php',
202
						'wikidataquery-url' => ''
203
					]
204
				]
205
			],
206
			[
207
				[
208
					'backend' => 'mongodb',
209
					'mongodb' => []
210
				]
211
			],
212
			[
213
				[
214
					'backend' => 'api',
215
					'api' => [
216
						'url' => 'http://www.wikidata.org/w/api.php'
217
					],
218
					'cache' => [
219
						'memcached' => 'toto'
220
					]
221
				]
222
			],
223
			[
224
				[
225
					'backend' => 'api',
226
					'api' => [
227
						'url' => 'http://www.wikidata.org/w/api.php'
228
					],
229
					'cache' => [
230
						'lifetime' => 'tata'
231
					]
232
				]
233
			],
234
			[
235
				[
236
					'backend' => 'api',
237
					'api' => [
238
						'url' => 'http://www.wikidata.org/w/api.php'
239
					],
240
					'cache' => [
241
						'array' => 'tata'
242
					]
243
				]
244
			],
245
			[
246
				[
247
					'backend' => 'api',
248
					'api' => [
249
						'url' => 'http://www.wikidata.org/w/api.php'
250
					],
251
					'cache' => [
252
						'memcached' => [
253
							'host' => []
254
						]
255
					]
256
				]
257
			],
258
			[
259
				[
260
					'backend' => 'api',
261
					'api' => [
262
						'url' => 'http://www.wikidata.org/w/api.php'
263
					],
264
					'cache' => [
265
						'memcached' => [
266
							'port' => 'foo'
267
						]
268
					]
269
				]
270
			],
271
		];
272
	}
273
}
274