1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Sandro Keil (https://sandro-keil.de) |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/sandrokeil/interop-config for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2015-2016 Sandro Keil |
7
|
|
|
* @license http://github.com/sandrokeil/interop-config/blob/master/LICENSE.md New BSD License |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types = 1); |
11
|
|
|
|
12
|
|
|
namespace InteropTest\Config; |
13
|
|
|
|
14
|
|
|
use Interop\Config\Exception\InvalidArgumentException; |
15
|
|
|
use Interop\Config\Exception\MandatoryOptionNotFoundException; |
16
|
|
|
use Interop\Config\Exception\OptionNotFoundException; |
17
|
|
|
use Interop\Config\Exception\UnexpectedValueException; |
18
|
|
|
use InteropTest\Config\TestAsset\ConnectionConfiguration; |
19
|
|
|
use InteropTest\Config\TestAsset\ConnectionContainerIdConfiguration; |
20
|
|
|
use InteropTest\Config\TestAsset\ConnectionDefaultOptionsMandatoryContainetIdConfiguration; |
21
|
|
|
use InteropTest\Config\TestAsset\ConnectionMandatoryConfiguration; |
22
|
|
|
use InteropTest\Config\TestAsset\ConnectionMandatoryContainerIdConfiguration; |
23
|
|
|
use InteropTest\Config\TestAsset\ConnectionMandatoryRecursiveArrayIteratorContainerIdConfiguration; |
24
|
|
|
use InteropTest\Config\TestAsset\ConnectionMandatoryRecursiveContainerIdConfiguration; |
25
|
|
|
use InteropTest\Config\TestAsset\FlexibleConfiguration; |
26
|
|
|
use InteropTest\Config\TestAsset\PackageDefaultAndMandatoryOptionsConfiguration; |
27
|
|
|
use InteropTest\Config\TestAsset\PackageDefaultOptionsConfiguration; |
28
|
|
|
use InteropTest\Config\TestAsset\PlainConfiguration; |
29
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* ConfigurationTraitTest |
33
|
|
|
* |
34
|
|
|
* Tests integrity of \Interop\Config\ConfigurationTrait |
35
|
|
|
*/ |
36
|
|
|
class ConfigurationTraitTest extends TestCase |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Class under test |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $cut = 'Interop\Config\ConfigurationTrait'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Tests options() should throw exception if config parameter is not an array |
47
|
|
|
* |
48
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
49
|
|
|
*/ |
50
|
|
|
public function testOptionsThrowsInvalidArgumentExceptionIfConfigIsNotAnArray(): void |
51
|
|
|
{ |
52
|
|
|
$stub = new ConnectionConfiguration(); |
53
|
|
|
|
54
|
|
|
$this->assertException(UnexpectedValueException::class, 'position is "doctrine"'); |
55
|
|
|
|
56
|
|
|
$stub->options(['doctrine' => new \stdClass()]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Tests canRetrieveOptions() : void |
61
|
|
|
* |
62
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
63
|
|
|
*/ |
64
|
|
|
public function testCanRetrieveOptions(): void |
65
|
|
|
{ |
66
|
|
|
$stub = new ConnectionConfiguration(); |
67
|
|
|
|
68
|
|
|
self::assertSame(false, $stub->canRetrieveOptions('')); |
|
|
|
|
69
|
|
|
self::assertSame(false, $stub->canRetrieveOptions(new \stdClass())); |
|
|
|
|
70
|
|
|
self::assertSame(false, $stub->canRetrieveOptions(null)); |
|
|
|
|
71
|
|
|
|
72
|
|
|
self::assertSame( |
73
|
|
|
false, |
74
|
|
|
$stub->canRetrieveOptions(['doctrine' => ['invalid' => ['default' => ['params' => '']]]]) |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
self::assertSame( |
78
|
|
|
false, |
79
|
|
|
$stub->canRetrieveOptions(['doctrine' => ['connection' => new \stdClass()]]) |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
self::assertSame(true, $stub->canRetrieveOptions($this->getTestConfig())); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Tests canRetrieveOptions() : void |
87
|
|
|
* |
88
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
89
|
|
|
*/ |
90
|
|
|
public function testCanRetrieveOptionsWithContainerId(): void |
91
|
|
|
{ |
92
|
|
|
$stub = new ConnectionContainerIdConfiguration(); |
93
|
|
|
|
94
|
|
|
self::assertSame(false, $stub->canRetrieveOptions(['doctrine' => ['connection' => null]]), 'orm_default'); |
95
|
|
|
|
96
|
|
|
self::assertSame( |
97
|
|
|
false, |
98
|
|
|
$stub->canRetrieveOptions(['doctrine' => ['connection' => ['invalid' => ['test' => 1]]]], 'orm_default') |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
self::assertSame( |
102
|
|
|
false, |
103
|
|
|
$stub->canRetrieveOptions( |
104
|
|
|
[ |
105
|
|
|
'doctrine' => [ |
106
|
|
|
'connection' => [ |
107
|
|
|
'orm_default' => new \stdClass(), |
108
|
|
|
], |
109
|
|
|
], |
110
|
|
|
], |
111
|
|
|
'orm_default' |
112
|
|
|
) |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
self::assertSame(true, $stub->canRetrieveOptions($this->getTestConfig(), 'orm_default')); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Tests options() should throw exception if config id is provided but RequiresConfigId interface is not implemented |
120
|
|
|
* |
121
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
122
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
123
|
|
|
*/ |
124
|
|
|
public function testOptionsThrowsInvalidArgumentExIfConfigIdIsProvidedButRequiresConfigIdIsNotImplemented(): void |
125
|
|
|
{ |
126
|
|
|
$stub = new ConnectionConfiguration(); |
127
|
|
|
|
128
|
|
|
self::assertFalse($stub->canRetrieveOptions(['doctrine' => []], 'configId')); |
129
|
|
|
|
130
|
|
|
$this->assertException(InvalidArgumentException::class, 'The factory'); |
131
|
|
|
|
132
|
|
|
$stub->options(['doctrine' => []], 'configId'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Tests options() should throw exception if config id is missing but RequiresConfigId interface is implemented |
137
|
|
|
* |
138
|
|
|
* @dataProvider providerConfig |
139
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
140
|
|
|
* @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions |
141
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
142
|
|
|
*/ |
143
|
|
|
public function testOptionsThrowsOptionNotFoundExceptionIfConfigIdIsMissingWithRequiresConfigId($config): void |
144
|
|
|
{ |
145
|
|
|
$stub = new ConnectionContainerIdConfiguration(); |
146
|
|
|
|
147
|
|
|
$this->assertException(OptionNotFoundException::class, 'The configuration'); |
148
|
|
|
|
149
|
|
|
self::assertFalse($stub->canRetrieveOptions($config, null)); |
150
|
|
|
|
151
|
|
|
$stub->options($config, null); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Tests options() should throw exception if no vendor config is available |
156
|
|
|
* |
157
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
158
|
|
|
* @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions |
159
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
160
|
|
|
*/ |
161
|
|
|
public function testOptionsThrowsOptionNotFoundExceptionIfNoVendorConfigIsAvailable(): void |
162
|
|
|
{ |
163
|
|
|
$stub = new ConnectionConfiguration(); |
164
|
|
|
|
165
|
|
|
$config = ['doctrine' => []]; |
166
|
|
|
|
167
|
|
|
self::assertFalse($stub->canRetrieveOptions($config)); |
168
|
|
|
|
169
|
|
|
$this->assertException(OptionNotFoundException::class, 'doctrine'); |
170
|
|
|
|
171
|
|
|
$stub->options($config); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Tests options() should throw exception if no package option is available |
176
|
|
|
* |
177
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
178
|
|
|
* @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions |
179
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
180
|
|
|
*/ |
181
|
|
|
public function testOptionsThrowsOptionNotFoundExceptionIfNoPackageOptionIsAvailable(): void |
182
|
|
|
{ |
183
|
|
|
$stub = new ConnectionConfiguration(); |
184
|
|
|
|
185
|
|
|
$config = ['doctrine' => ['connection' => null]]; |
186
|
|
|
|
187
|
|
|
self::assertFalse($stub->canRetrieveOptions($config)); |
188
|
|
|
|
189
|
|
|
$this->assertException( |
190
|
|
|
OptionNotFoundException::class, |
191
|
|
|
'No options set for configuration "doctrine.connection"' |
192
|
|
|
); |
193
|
|
|
|
194
|
|
|
$stub->options($config); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Tests options() should throw exception if no container id option is available |
199
|
|
|
* |
200
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
201
|
|
|
* @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions |
202
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
203
|
|
|
*/ |
204
|
|
|
public function testOptionsThrowsOptionNotFoundExceptionIfNoContainerIdOptionIsAvailable(): void |
205
|
|
|
{ |
206
|
|
|
$stub = new ConnectionContainerIdConfiguration(); |
207
|
|
|
|
208
|
|
|
$config = ['doctrine' => ['connection' => ['orm_default' => null]]]; |
209
|
|
|
|
210
|
|
|
self::assertFalse($stub->canRetrieveOptions($config, 'orm_default')); |
211
|
|
|
|
212
|
|
|
$this->assertException(OptionNotFoundException::class, '"doctrine.connection.orm_default"'); |
213
|
|
|
|
214
|
|
|
$stub->options($config, 'orm_default'); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Tests options() should throw exception if a dimension is not available |
219
|
|
|
* |
220
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
221
|
|
|
* @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions |
222
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
223
|
|
|
*/ |
224
|
|
|
public function testOptionsThrowsOptionNotFoundExceptionIfDimensionIsNotAvailable(): void |
225
|
|
|
{ |
226
|
|
|
$stub = new FlexibleConfiguration(); |
227
|
|
|
|
228
|
|
|
$config = ['one' => ['two' => ['three' => ['invalid' => ['dimension']]]]]; |
229
|
|
|
|
230
|
|
|
self::assertFalse($stub->canRetrieveOptions($config)); |
231
|
|
|
|
232
|
|
|
$this->assertException(OptionNotFoundException::class, '"one.two.three.four"'); |
233
|
|
|
|
234
|
|
|
$stub->options(['one' => ['two' => ['three' => ['invalid' => ['dimension']]]]]); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Tests if options() works with dimensions, default options and mandatory options if no config is available |
239
|
|
|
* |
240
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
241
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
242
|
|
|
*/ |
243
|
|
|
public function testOptionsThrowsExceptionIfMandatoryOptionsWithDefaultOptionsSetAndNoConfigurationIsSet(): void |
244
|
|
|
{ |
245
|
|
|
$stub = new PackageDefaultAndMandatoryOptionsConfiguration(); |
246
|
|
|
|
247
|
|
|
self::assertFalse($stub->canRetrieveOptions([])); |
248
|
|
|
|
249
|
|
|
$this->assertException(OptionNotFoundException::class, '"vendor"'); |
250
|
|
|
|
251
|
|
|
$stub->options([]); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Tests options() should throw exception if retrieved options not an array or \ArrayAccess |
256
|
|
|
* |
257
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
258
|
|
|
* @covers \Interop\Config\Exception\UnexpectedValueException::invalidOptions |
259
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
260
|
|
|
*/ |
261
|
|
|
public function testOptionsThrowsUnexpectedValueExceptionIfRetrievedOptionsNotAnArrayOrArrayAccess(): void |
262
|
|
|
{ |
263
|
|
|
$stub = new ConnectionContainerIdConfiguration(); |
264
|
|
|
|
265
|
|
|
$config = ['doctrine' => ['connection' => ['orm_default' => new \stdClass()]]]; |
266
|
|
|
|
267
|
|
|
self::assertFalse($stub->canRetrieveOptions($config, 'orm_default')); |
268
|
|
|
|
269
|
|
|
$this->assertException(UnexpectedValueException::class, 'Configuration must either be of'); |
270
|
|
|
|
271
|
|
|
$stub->options($config, 'orm_default'); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Tests if options() works with container id |
276
|
|
|
* |
277
|
|
|
* @dataProvider providerConfig |
278
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
279
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
280
|
|
|
*/ |
281
|
|
|
public function testOptionsReturnsDataWithContainerId($config): void |
282
|
|
|
{ |
283
|
|
|
$stub = new ConnectionContainerIdConfiguration(); |
284
|
|
|
|
285
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
286
|
|
|
|
287
|
|
|
$options = $stub->options($config, 'orm_default'); |
288
|
|
|
|
289
|
|
|
self::assertArrayHasKey('driverClass', $options); |
290
|
|
|
self::assertArrayHasKey('params', $options); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Tests if options() works without container id |
295
|
|
|
* |
296
|
|
|
* @dataProvider providerConfig |
297
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
298
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
299
|
|
|
*/ |
300
|
|
|
public function testOptionsReturnsData($config): void |
301
|
|
|
{ |
302
|
|
|
$stub = new ConnectionConfiguration(); |
303
|
|
|
|
304
|
|
|
self::assertTrue($stub->canRetrieveOptions($config)); |
305
|
|
|
|
306
|
|
|
$options = $stub->options($config); |
307
|
|
|
|
308
|
|
|
self::assertArrayHasKey('orm_default', $options); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Tests if options() works with flexible dimensions |
313
|
|
|
* |
314
|
|
|
* @dataProvider providerConfig |
315
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
316
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
317
|
|
|
*/ |
318
|
|
|
public function testOptionsReturnsDataWithFlexibleDimensions($config): void |
319
|
|
|
{ |
320
|
|
|
$stub = new FlexibleConfiguration(); |
321
|
|
|
|
322
|
|
|
self::assertTrue($stub->canRetrieveOptions($config)); |
323
|
|
|
|
324
|
|
|
$options = $stub->options($config); |
325
|
|
|
|
326
|
|
|
self::assertArrayHasKey('name', $options); |
327
|
|
|
self::assertArrayHasKey('class', $options); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Tests if options() works with no dimensions |
332
|
|
|
* |
333
|
|
|
* @dataProvider providerConfig |
334
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
335
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
336
|
|
|
*/ |
337
|
|
|
public function testOptionsReturnsDataWithNoDimensions($config): void |
338
|
|
|
{ |
339
|
|
|
$stub = new PlainConfiguration(); |
340
|
|
|
|
341
|
|
|
self::assertTrue($stub->canRetrieveOptions($config)); |
342
|
|
|
|
343
|
|
|
$options = $stub->options($config); |
344
|
|
|
|
345
|
|
|
self::assertArrayHasKey('doctrine', $options); |
346
|
|
|
self::assertArrayHasKey('one', $options); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Tests if options() works with default options |
351
|
|
|
* |
352
|
|
|
* @dataProvider providerConfig |
353
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
354
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
355
|
|
|
*/ |
356
|
|
|
public function testOptionsReturnsDataWithDefaultOptions($config): void |
357
|
|
|
{ |
358
|
|
|
$stub = new ConnectionDefaultOptionsMandatoryContainetIdConfiguration(); |
359
|
|
|
|
360
|
|
|
unset($config['doctrine']['connection']['orm_default']['params']['host']); |
361
|
|
|
unset($config['doctrine']['connection']['orm_default']['params']['port']); |
362
|
|
|
|
363
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
364
|
|
|
$options = $stub->options($config, 'orm_default'); |
365
|
|
|
$defaultOptions = $stub->defaultOptions(); |
366
|
|
|
|
367
|
|
|
self::assertArrayHasKey('params', $options); |
368
|
|
|
self::assertSame($options['params']['host'], $defaultOptions['params']['host']); |
369
|
|
|
self::assertSame($options['params']['port'], $defaultOptions['params']['port']); |
370
|
|
|
self::assertSame( |
371
|
|
|
$options['params']['user'], |
372
|
|
|
$config['doctrine']['connection']['orm_default']['params']['user'] |
373
|
|
|
); |
374
|
|
|
|
375
|
|
|
$config = $this->getTestConfig(); |
376
|
|
|
|
377
|
|
|
# remove main index key |
378
|
|
|
unset($config['doctrine']['connection']['orm_default']['params']); |
379
|
|
|
|
380
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
381
|
|
|
$options = $stub->options($config, 'orm_default'); |
382
|
|
|
|
383
|
|
|
self::assertArrayHasKey('params', $options); |
384
|
|
|
self::assertSame($options['params']['host'], $defaultOptions['params']['host']); |
385
|
|
|
self::assertSame($options['params']['port'], $defaultOptions['params']['port']); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Tests if options() works with dimensions and default options if no config is available |
390
|
|
|
* |
391
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
392
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
393
|
|
|
*/ |
394
|
|
|
public function testOptionsReturnsPackageDataWithDefaultOptionsIfNoConfigurationIsSet(): void |
395
|
|
|
{ |
396
|
|
|
$stub = new PackageDefaultOptionsConfiguration(); |
397
|
|
|
|
398
|
|
|
self::assertTrue($stub->canRetrieveOptions([])); |
399
|
|
|
|
400
|
|
|
$expected = [ |
401
|
|
|
'minLength' => 2, |
402
|
|
|
'maxLength' => 10, |
403
|
|
|
]; |
404
|
|
|
|
405
|
|
|
$options = $stub->options([]); |
406
|
|
|
|
407
|
|
|
self::assertSame($expected, $options); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Tests if options() works default options and default options not override provided options |
412
|
|
|
* |
413
|
|
|
* @dataProvider providerConfig |
414
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
415
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
416
|
|
|
*/ |
417
|
|
|
public function testOptionsThatDefaultOptionsNotOverrideProvidedOptions($config): void |
418
|
|
|
{ |
419
|
|
|
$stub = new ConnectionDefaultOptionsMandatoryContainetIdConfiguration(); |
420
|
|
|
|
421
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
422
|
|
|
$options = $stub->options($config, 'orm_default'); |
423
|
|
|
|
424
|
|
|
self::assertArrayHasKey('params', $options); |
425
|
|
|
self::assertSame( |
426
|
|
|
$options['params']['host'], |
427
|
|
|
$config['doctrine']['connection']['orm_default']['params']['host'] |
428
|
|
|
); |
429
|
|
|
self::assertSame( |
430
|
|
|
$options['params']['port'], |
431
|
|
|
$config['doctrine']['connection']['orm_default']['params']['port'] |
432
|
|
|
); |
433
|
|
|
self::assertSame( |
434
|
|
|
$options['params']['user'], |
435
|
|
|
$config['doctrine']['connection']['orm_default']['params']['user'] |
436
|
|
|
); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* Tests if options() works with mandatory options interface |
441
|
|
|
* |
442
|
|
|
* @dataProvider providerConfig |
443
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
444
|
|
|
* @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions |
445
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
446
|
|
|
*/ |
447
|
|
|
public function testOptionsChecksMandatoryOptions($config): void |
448
|
|
|
{ |
449
|
|
|
$stub = new ConnectionMandatoryConfiguration(); |
450
|
|
|
|
451
|
|
|
self::assertTrue($stub->canRetrieveOptions($config)); |
452
|
|
|
$options = $stub->options($config); |
453
|
|
|
|
454
|
|
|
self::assertArrayHasKey('orm_default', $options); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* Tests if options() works with mandatory options interface |
459
|
|
|
* |
460
|
|
|
* @dataProvider providerConfig |
461
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
462
|
|
|
* @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions |
463
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
464
|
|
|
*/ |
465
|
|
|
public function testOptionsChecksMandatoryOptionsWithContainerId($config): void |
466
|
|
|
{ |
467
|
|
|
$stub = new ConnectionMandatoryContainerIdConfiguration(); |
468
|
|
|
|
469
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
470
|
|
|
$options = $stub->options($config, 'orm_default'); |
471
|
|
|
|
472
|
|
|
self::assertArrayHasKey('driverClass', $options); |
473
|
|
|
self::assertArrayHasKey('params', $options); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* Tests if options() throws a runtime exception if mandatory option is missing |
478
|
|
|
* |
479
|
|
|
* @dataProvider providerConfig |
480
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
481
|
|
|
* @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions |
482
|
|
|
* @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption |
483
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
484
|
|
|
*/ |
485
|
|
|
public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfMandatoryOptionIsMissing($config): void |
486
|
|
|
{ |
487
|
|
|
$stub = new ConnectionMandatoryContainerIdConfiguration(); |
488
|
|
|
|
489
|
|
|
unset($config['doctrine']['connection']['orm_default']['params']); |
490
|
|
|
|
491
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
492
|
|
|
|
493
|
|
|
$this->assertException(MandatoryOptionNotFoundException::class, 'Mandatory option "params"'); |
494
|
|
|
$stub->options($config, 'orm_default'); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Tests if options() throws a runtime exception if a recursive mandatory option is missing |
499
|
|
|
* |
500
|
|
|
* @dataProvider providerConfig |
501
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
502
|
|
|
* @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions |
503
|
|
|
* @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption |
504
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
505
|
|
|
*/ |
506
|
|
|
public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfMandatoryOptionRecursiveIsMissing($config): void |
507
|
|
|
{ |
508
|
|
|
$stub = new ConnectionMandatoryRecursiveContainerIdConfiguration(); |
509
|
|
|
|
510
|
|
|
unset($config['doctrine']['connection']['orm_default']['params']['dbname']); |
511
|
|
|
|
512
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
513
|
|
|
|
514
|
|
|
$this->assertException(MandatoryOptionNotFoundException::class, 'Mandatory option "dbname"'); |
515
|
|
|
$stub->options($config, 'orm_default'); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* Tests options() with recursive mandatory options check |
520
|
|
|
* |
521
|
|
|
* @dataProvider providerConfig |
522
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
523
|
|
|
* @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions |
524
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
525
|
|
|
*/ |
526
|
|
|
public function testOptionsWithRecursiveMandatoryOptionCheck($config): void |
527
|
|
|
{ |
528
|
|
|
$stub = new ConnectionMandatoryRecursiveContainerIdConfiguration(); |
529
|
|
|
|
530
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
531
|
|
|
self::assertArrayHasKey('params', $stub->options($config, 'orm_default')); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Tests options() with recursive mandatory options as array iterator |
536
|
|
|
* |
537
|
|
|
* @dataProvider providerConfig |
538
|
|
|
* @covers \Interop\Config\ConfigurationTrait::options |
539
|
|
|
* @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions |
540
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
541
|
|
|
*/ |
542
|
|
|
public function testOptionsWithRecursiveArrayIteratorMandatoryOptionCheck($config): void |
543
|
|
|
{ |
544
|
|
|
$stub = new ConnectionMandatoryRecursiveArrayIteratorContainerIdConfiguration(); |
545
|
|
|
|
546
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
547
|
|
|
self::assertArrayHasKey('params', $stub->options($config, 'orm_default')); |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* Tests if options() throws a runtime exception if a recursive mandatory option is missing |
552
|
|
|
* |
553
|
|
|
* @dataProvider providerConfig |
554
|
|
|
* @covers \Interop\Config\ConfigurationTrait::optionsWithFallback |
555
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
556
|
|
|
*/ |
557
|
|
|
public function testOptionsWithFallback($config): void |
558
|
|
|
{ |
559
|
|
|
$stub = new ConnectionDefaultOptionsMandatoryContainetIdConfiguration(); |
560
|
|
|
|
561
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
562
|
|
|
|
563
|
|
|
self::assertArrayHasKey('params', $stub->optionsWithFallback([])); |
564
|
|
|
self::assertArrayHasKey('params', $stub->optionsWithFallback($config, 'orm_default')); |
565
|
|
|
self::assertArrayHasKey('driverClass', $stub->optionsWithFallback($config, 'orm_default')); |
566
|
|
|
|
567
|
|
|
unset($config['doctrine']['connection']['orm_default']['params']); |
568
|
|
|
|
569
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
570
|
|
|
self::assertArrayHasKey('params', $stub->optionsWithFallback($config)); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* Tests if options() throws a runtime exception if a recursive mandatory option is missing |
575
|
|
|
* |
576
|
|
|
* @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions |
577
|
|
|
* @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption |
578
|
|
|
* @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions |
579
|
|
|
*/ |
580
|
|
|
public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfOptionsAreEmpty(): void |
581
|
|
|
{ |
582
|
|
|
$stub = new ConnectionMandatoryRecursiveContainerIdConfiguration(); |
583
|
|
|
|
584
|
|
|
$config = ['doctrine' => ['connection' => ['orm_default' => []]]]; |
585
|
|
|
|
586
|
|
|
self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); |
587
|
|
|
|
588
|
|
|
$this->assertException(MandatoryOptionNotFoundException::class, 'Mandatory option "params"'); |
589
|
|
|
|
590
|
|
|
$stub->options($config, 'orm_default'); |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
public function providerConfig(): array |
594
|
|
|
{ |
595
|
|
|
return [ |
596
|
|
|
[$this->getTestConfig()], |
597
|
|
|
[new \ArrayObject($this->getTestConfig())], |
598
|
|
|
]; |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
/** |
602
|
|
|
* Returns test config |
603
|
|
|
* |
604
|
|
|
* @return array |
605
|
|
|
*/ |
606
|
|
|
private function getTestConfig(): array |
607
|
|
|
{ |
608
|
|
|
// Load the user-defined test configuration file, if it exists; otherwise, load default |
609
|
|
|
if (is_readable('test/TestConfig.php')) { |
610
|
|
|
$config = require 'test/testing.config.php'; |
611
|
|
|
} else { |
612
|
|
|
$config = require 'test/testing.config.php.dist'; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
return $config; |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* @param $exception |
620
|
|
|
* @param $message |
621
|
|
|
*/ |
622
|
|
|
private function assertException($exception, $message): void |
623
|
|
|
{ |
624
|
|
|
$this->expectException($exception); |
625
|
|
|
$this->expectExceptionMessage($message); |
626
|
|
|
} |
627
|
|
|
} |
628
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: