Completed
Pull Request — master (#29)
by Sandro
06:42
created

testCanRetrieveOptionsWithContainerId()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 27
rs 8.8571
cc 1
eloc 14
nc 1
nop 0
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
namespace InteropTest\Config;
11
12
use Interop\Config\Exception\InvalidArgumentException;
13
use Interop\Config\Exception\MandatoryOptionNotFoundException;
14
use Interop\Config\Exception\OptionNotFoundException;
15
use Interop\Config\Exception\UnexpectedValueException;
16
use InteropTest\Config\TestAsset\ConnectionConfiguration;
17
use InteropTest\Config\TestAsset\ConnectionContainerIdConfiguration;
18
use InteropTest\Config\TestAsset\ConnectionDefaultOptionsConfiguration;
19
use InteropTest\Config\TestAsset\ConnectionMandatoryConfiguration;
20
use InteropTest\Config\TestAsset\ConnectionMandatoryContainerIdConfiguration;
21
use InteropTest\Config\TestAsset\ConnectionMandatoryRecursiveContainerIdConfiguration;
22
use InteropTest\Config\TestAsset\FlexibleConfiguration;
23
use InteropTest\Config\TestAsset\PackageDefaultAndMandatoryOptionsConfiguration;
24
use InteropTest\Config\TestAsset\PackageDefaultOptionsConfiguration;
25
use InteropTest\Config\TestAsset\PlainConfiguration;
26
use PHPUnit_Framework_TestCase as TestCase;
27
28
/**
29
 * ConfigurationTraitTest
30
 *
31
 * Tests integrity of \Interop\Config\ConfigurationTrait
32
 */
33
class ConfigurationTraitTest extends TestCase
34
{
35
    /**
36
     * Class under test
37
     *
38
     * @var string
39
     */
40
    protected $cut = 'Interop\Config\ConfigurationTrait';
41
42
    /**
43
     * Tests options() should throw exception if config parameter is not an array
44
     *
45
     * @covers \Interop\Config\ConfigurationTrait::options
46
     */
47
    public function testOptionsThrowsInvalidArgumentExceptionIfConfigIsNotAnArray()
48
    {
49
        $stub = new ConnectionConfiguration();
50
51
        $this->assertException(UnexpectedValueException::class, 'position is "doctrine"');
52
53
        $stub->options(['doctrine' => new \stdClass()]);
54
    }
55
56
    /**
57
     * Tests canRetrieveOptions()
58
     *
59
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
60
     */
61
    public function testCanRetrieveOptions()
62
    {
63
        $stub = new ConnectionConfiguration();
64
65
        self::assertSame(false, $stub->canRetrieveOptions(''));
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a array|object<ArrayAccess>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
        self::assertSame(false, $stub->canRetrieveOptions(new \stdClass()));
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, but the function expects a array|object<ArrayAccess>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
        self::assertSame(false, $stub->canRetrieveOptions(null));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array|object<ArrayAccess>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
69
        self::assertSame(
70
            false,
71
            $stub->canRetrieveOptions(['doctrine' => ['invalid' => ['default' => ['params' => '']]]])
72
        );
73
74
        self::assertSame(
75
            false,
76
            $stub->canRetrieveOptions(['doctrine' => ['connection' => new \stdClass()]])
77
        );
78
79
        self::assertSame(true, $stub->canRetrieveOptions($this->getTestConfig()));
80
    }
81
82
    /**
83
     * Tests canRetrieveOptions()
84
     *
85
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
86
     */
87
    public function testCanRetrieveOptionsWithContainerId()
88
    {
89
        $stub = new ConnectionContainerIdConfiguration();
90
91
        self::assertSame(false, $stub->canRetrieveOptions(['doctrine' => ['connection' => null]]), 'orm_default');
92
93
        self::assertSame(
94
            false,
95
            $stub->canRetrieveOptions(['doctrine' => ['connection' => ['invalid' => ['test' => 1]]]], 'orm_default')
96
        );
97
98
        self::assertSame(
99
            false,
100
            $stub->canRetrieveOptions(
101
                [
102
                    'doctrine' => [
103
                        'connection' => [
104
                            'orm_default' => new \stdClass()
105
                        ]
106
                    ]
107
                ],
108
                'orm_default'
109
            )
110
        );
111
112
        self::assertSame(true, $stub->canRetrieveOptions($this->getTestConfig(), 'orm_default'));
113
    }
114
115
    /**
116
     * Tests options() should throw exception if config id is provided but RequiresConfigId interface is not implemented
117
     *
118
     * @covers \Interop\Config\ConfigurationTrait::options
119
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
120
     */
121
    public function testOptionsThrowsInvalidArgumentExceptionIfConfigIdIsProvidedButRequiresConfigIdIsNotImplemented()
122
    {
123
        $stub = new ConnectionConfiguration();
124
125
        self::assertFalse($stub->canRetrieveOptions(['doctrine' => []], 'configId'));
126
127
        $this->assertException(InvalidArgumentException::class, 'The factory');
128
129
        $stub->options(['doctrine' => []], 'configId');
130
    }
131
132
    /**
133
     * Tests options() should throw exception if config id is missing but RequiresConfigId interface is implemented
134
     *
135
     * @covers \Interop\Config\ConfigurationTrait::options
136
     * @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions
137
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
138
     */
139
    public function testOptionsThrowsOptionNotFoundExceptionIfConfigIdIsMissingButRequiresConfigIdIsImplemented()
140
    {
141
        $stub = new ConnectionContainerIdConfiguration();
142
143
        $config = $this->getTestConfig();
144
145
        $this->assertException(OptionNotFoundException::class, 'The configuration');
146
147
        self::assertFalse($stub->canRetrieveOptions($config, null));
148
149
        $stub->options($config, null);
150
    }
151
152
    /**
153
     * Tests options() should throw exception if no vendor config is available
154
     *
155
     * @covers \Interop\Config\ConfigurationTrait::options
156
     * @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions
157
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
158
     */
159
    public function testOptionsThrowsOptionNotFoundExceptionIfNoVendorConfigIsAvailable()
160
    {
161
        $stub = new ConnectionConfiguration();
162
163
        $config = ['doctrine' => []];
164
165
        self::assertFalse($stub->canRetrieveOptions($config));
166
167
        $this->assertException(OptionNotFoundException::class, 'doctrine');
168
169
        $stub->options($config);
170
    }
171
172
    /**
173
     * Tests options() should throw exception if no package option is available
174
     *
175
     * @covers \Interop\Config\ConfigurationTrait::options
176
     * @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions
177
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
178
     */
179
    public function testOptionsThrowsOptionNotFoundExceptionIfNoPackageOptionIsAvailable()
180
    {
181
        $stub = new ConnectionConfiguration();
182
183
        $config = ['doctrine' => ['connection' => null]];
184
185
        self::assertFalse($stub->canRetrieveOptions($config));
186
187
        $this->assertException(
188
            OptionNotFoundException::class,
189
            'No options set for configuration "doctrine.connection"'
190
        );
191
192
        $stub->options($config);
193
    }
194
195
    /**
196
     * Tests options() should throw exception if no container id option is available
197
     *
198
     * @covers \Interop\Config\ConfigurationTrait::options
199
     * @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions
200
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
201
     */
202
    public function testOptionsThrowsOptionNotFoundExceptionIfNoContainerIdOptionIsAvailable()
203
    {
204
        $stub = new ConnectionContainerIdConfiguration();
205
206
        $config = ['doctrine' => ['connection' => ['orm_default' => null]]];
207
208
        self::assertFalse($stub->canRetrieveOptions($config, 'orm_default'));
209
210
        $this->assertException(OptionNotFoundException::class, '"doctrine.connection.orm_default"');
211
212
        $stub->options($config, 'orm_default');
213
    }
214
215
    /**
216
     * Tests options() should throw exception if a dimension is not available
217
     *
218
     * @covers \Interop\Config\ConfigurationTrait::options
219
     * @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions
220
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
221
     */
222
    public function testOptionsThrowsOptionNotFoundExceptionIfDimensionIsNotAvailable()
223
    {
224
        $stub = new FlexibleConfiguration();
225
226
        $config = ['one' => ['two' => ['three' => ['invalid' => ['dimension']]]]];
227
228
        self::assertFalse($stub->canRetrieveOptions($config));
229
230
        $this->assertException(OptionNotFoundException::class, '"one.two.three.four"');
231
232
        $stub->options(['one' => ['two' => ['three' => ['invalid' => ['dimension']]]]]);
233
    }
234
235
    /**
236
     * Tests if options() works with dimensions, default options and mandatory options if no config is available
237
     *
238
     * @covers \Interop\Config\ConfigurationTrait::options
239
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
240
     */
241
    public function testOptionsThrowsExceptionIfMandatoryOptionsWithDefaultOptionsSetAndNoConfigurationIsSet()
242
    {
243
        $stub = new PackageDefaultAndMandatoryOptionsConfiguration();
244
245
        self::assertFalse($stub->canRetrieveOptions([]));
246
247
        $this->assertException(OptionNotFoundException::class, '"vendor"');
248
249
        $stub->options([]);
250
    }
251
252
    /**
253
     * Tests options() should throw exception if retrieved options not an array or \ArrayAccess
254
     *
255
     * @covers \Interop\Config\ConfigurationTrait::options
256
     * @covers \Interop\Config\Exception\UnexpectedValueException::invalidOptions
257
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
258
     */
259
    public function testOptionsThrowsUnexpectedValueExceptionIfRetrievedOptionsNotAnArrayOrArrayAccess()
260
    {
261
        $stub = new ConnectionContainerIdConfiguration();
262
263
        $config = ['doctrine' => ['connection' => ['orm_default' => new \stdClass()]]];
264
265
        self::assertFalse($stub->canRetrieveOptions($config, 'orm_default'));
266
267
        $this->assertException(UnexpectedValueException::class, 'Configuration must either be of');
268
269
        $stub->options($config, 'orm_default');
270
    }
271
272
    /**
273
     * Tests if options() works with container id
274
     *
275
     * @covers \Interop\Config\ConfigurationTrait::options
276
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
277
     */
278
    public function testOptionsReturnsDataWithContainerId()
279
    {
280
        $stub = new ConnectionContainerIdConfiguration();
281
282
        $testConfig = $this->getTestConfig();
283
284
        self::assertTrue($stub->canRetrieveOptions($testConfig, 'orm_default'));
285
286
        $options = $stub->options($testConfig, 'orm_default');
287
288
        self::assertArrayHasKey('driverClass', $options);
289
        self::assertArrayHasKey('params', $options);
290
    }
291
292
    /**
293
     * Tests if options() works without container id
294
     *
295
     * @covers \Interop\Config\ConfigurationTrait::options
296
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
297
     */
298
    public function testOptionsReturnsData()
299
    {
300
        $stub = new ConnectionConfiguration();
301
302
        $testConfig = $this->getTestConfig();
303
304
        self::assertTrue($stub->canRetrieveOptions($testConfig));
305
306
        $options = $stub->options($testConfig);
307
308
        self::assertArrayHasKey('orm_default', $options);
309
    }
310
311
    /**
312
     * Tests if options() works with flexible dimensions
313
     *
314
     * @covers \Interop\Config\ConfigurationTrait::options
315
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
316
     */
317
    public function testOptionsReturnsDataWithFlexibleDimensions()
318
    {
319
        $stub = new FlexibleConfiguration();
320
321
        $testConfig = $this->getTestConfig();
322
323
        self::assertTrue($stub->canRetrieveOptions($testConfig));
324
325
        $options = $stub->options($testConfig);
326
327
        self::assertArrayHasKey('name', $options);
328
        self::assertArrayHasKey('class', $options);
329
    }
330
331
    /**
332
     * Tests if options() works with no dimensions
333
     *
334
     * @covers \Interop\Config\ConfigurationTrait::options
335
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
336
     */
337
    public function testOptionsReturnsDataWithNoDimensions()
338
    {
339
        $stub = new PlainConfiguration();
340
341
        $testConfig = $this->getTestConfig();
342
343
        self::assertTrue($stub->canRetrieveOptions($testConfig));
344
345
        $options = $stub->options($testConfig);
346
347
        self::assertArrayHasKey('doctrine', $options);
348
        self::assertArrayHasKey('one', $options);
349
    }
350
351
    /**
352
     * Tests if options() works with default options
353
     *
354
     * @covers \Interop\Config\ConfigurationTrait::options
355
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
356
     */
357
    public function testOptionsReturnsDataWithDefaultOptions()
358
    {
359
        $stub = new ConnectionDefaultOptionsConfiguration();
360
361
        $testConfig = $this->getTestConfig();
362
363
        unset($testConfig['doctrine']['connection']['orm_default']['params']['host']);
364
        unset($testConfig['doctrine']['connection']['orm_default']['params']['port']);
365
366
        self::assertTrue($stub->canRetrieveOptions($testConfig, 'orm_default'));
367
        $options = $stub->options($testConfig, 'orm_default');
368
369
        self::assertArrayHasKey('params', $options);
370
        self::assertSame($options['params']['host'], $stub->defaultOptions()['params']['host']);
371
        self::assertSame($options['params']['port'], $stub->defaultOptions()['params']['port']);
372
        self::assertSame(
373
            $options['params']['user'],
374
            $testConfig['doctrine']['connection']['orm_default']['params']['user']
375
        );
376
377
        $testConfig = $this->getTestConfig();
378
379
        # remove main index key
380
        unset($testConfig['doctrine']['connection']['orm_default']['params']);
381
382
        self::assertTrue($stub->canRetrieveOptions($testConfig, 'orm_default'));
383
        $options = $stub->options($testConfig, 'orm_default');
384
385
        self::assertArrayHasKey('params', $options);
386
        self::assertSame($options['params']['host'], $stub->defaultOptions()['params']['host']);
387
        self::assertSame($options['params']['port'], $stub->defaultOptions()['params']['port']);
388
    }
389
390
    /**
391
     * Tests if options() works with dimensions and default options if no config is available
392
     *
393
     * @covers \Interop\Config\ConfigurationTrait::options
394
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
395
     */
396
    public function testOptionsReturnsPackageDataWithDefaultOptionsIfNoConfigurationIsSet()
397
    {
398
        $stub = new PackageDefaultOptionsConfiguration();
399
400
        self::assertTrue($stub->canRetrieveOptions([]));
401
402
        $expected = [
403
            'minLength' => 2,
404
            'maxLength' => 10
405
        ];
406
407
        $options = $stub->options([]);
408
409
        self::assertSame($expected, $options);
410
    }
411
412
    /**
413
     * Tests if options() works default options and default options not override provided options
414
     *
415
     * @covers \Interop\Config\ConfigurationTrait::options
416
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
417
     */
418
    public function testOptionsThatDefaultOptionsNotOverrideProvidedOptions()
419
    {
420
        $stub = new ConnectionDefaultOptionsConfiguration();
421
422
        $testConfig = $this->getTestConfig();
423
424
        self::assertTrue($stub->canRetrieveOptions($testConfig, 'orm_default'));
425
        $options = $stub->options($testConfig, 'orm_default');
426
427
        self::assertArrayHasKey('params', $options);
428
        self::assertSame(
429
            $options['params']['host'],
430
            $testConfig['doctrine']['connection']['orm_default']['params']['host']
431
        );
432
        self::assertSame(
433
            $options['params']['port'],
434
            $testConfig['doctrine']['connection']['orm_default']['params']['port']
435
        );
436
        self::assertSame(
437
            $options['params']['user'],
438
            $testConfig['doctrine']['connection']['orm_default']['params']['user']
439
        );
440
    }
441
442
    /**
443
     * Tests if options() works with mandatory options interface
444
     *
445
     * @covers \Interop\Config\ConfigurationTrait::options
446
     * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions
447
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
448
     */
449
    public function testOptionsChecksMandatoryOptions()
450
    {
451
        $stub = new ConnectionMandatoryConfiguration();
452
453
        $testConfig = $this->getTestConfig();
454
455
        self::assertTrue($stub->canRetrieveOptions($testConfig));
456
        $options = $stub->options($testConfig);
457
458
        self::assertArrayHasKey('orm_default', $options);
459
    }
460
461
    /**
462
     * Tests if options() works with mandatory options interface
463
     *
464
     * @covers \Interop\Config\ConfigurationTrait::options
465
     * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions
466
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
467
     */
468
    public function testOptionsChecksMandatoryOptionsWithContainerId()
469
    {
470
        $stub = new ConnectionMandatoryContainerIdConfiguration();
471
472
        $testConfig = $this->getTestConfig();
473
474
        self::assertTrue($stub->canRetrieveOptions($testConfig, 'orm_default'));
475
        $options = $stub->options($testConfig, 'orm_default');
476
477
        self::assertArrayHasKey('driverClass', $options);
478
        self::assertArrayHasKey('params', $options);
479
    }
480
481
    /**
482
     * Tests if options() throws a runtime exception if mandatory option is missing
483
     *
484
     * @covers \Interop\Config\ConfigurationTrait::options
485
     * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions
486
     * @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption
487
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
488
     */
489
    public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfMandatoryOptionIsMissing()
490
    {
491
        $stub = new ConnectionMandatoryContainerIdConfiguration();
492
493
        $config = $this->getTestConfig();
494
        unset($config['doctrine']['connection']['orm_default']['params']);
495
496
        self::assertTrue($stub->canRetrieveOptions($config, 'orm_default'));
497
498
        $this->assertException(MandatoryOptionNotFoundException::class, 'Mandatory option "params"');
499
        $stub->options($config, 'orm_default');
500
    }
501
502
    /**
503
     * Tests if options() throws a runtime exception if a recursive mandatory option is missing
504
     *
505
     * @covers \Interop\Config\ConfigurationTrait::options
506
     * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions
507
     * @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption
508
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
509
     */
510
    public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfMandatoryOptionRecursiveIsMissing()
511
    {
512
        $stub = new ConnectionMandatoryRecursiveContainerIdConfiguration();
513
514
        $config = $this->getTestConfig();
515
516
        unset($config['doctrine']['connection']['orm_default']['params']['dbname']);
517
518
        self::assertTrue($stub->canRetrieveOptions($config, 'orm_default'));
519
520
        $this->assertException(MandatoryOptionNotFoundException::class, 'Mandatory option "dbname"');
521
        $stub->options($config, 'orm_default');
522
    }
523
524
    /**
525
     * Tests options() with recursive mandatory options check
526
     *
527
     * @covers \Interop\Config\ConfigurationTrait::options
528
     * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions
529
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
530
     */
531
    public function testOptionsWithRecursiveMandatoryOptionCheck()
532
    {
533
        $stub = new ConnectionMandatoryRecursiveContainerIdConfiguration();
534
535
        $config = $this->getTestConfig();
536
537
        self::assertTrue($stub->canRetrieveOptions($config, 'orm_default'));
538
        self::assertArrayHasKey('params', $stub->options($config, 'orm_default'));
539
    }
540
541
    /**
542
     * Tests if options() throws a runtime exception if a recursive mandatory option is missing
543
     *
544
     * @covers \Interop\Config\ConfigurationTrait::optionsWithFallback
545
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
546
     */
547
    public function testOptionsWithFallback()
548
    {
549
        $stub = new ConnectionDefaultOptionsConfiguration();
550
551
        $config = $this->getTestConfig();
552
        self::assertTrue($stub->canRetrieveOptions($config, 'orm_default'));
553
554
        self::assertArrayHasKey('params', $stub->optionsWithFallback([]));
555
        self::assertArrayHasKey('params', $stub->optionsWithFallback($config, 'orm_default'));
556
557
        unset($config['doctrine']['connection']['orm_default']['params']);
558
559
        self::assertTrue($stub->canRetrieveOptions($config, 'orm_default'));
560
        self::assertArrayHasKey('params', $stub->optionsWithFallback($config));
561
    }
562
563
    /**
564
     * Tests if options() throws a runtime exception if a recursive mandatory option is missing
565
     *
566
     * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions
567
     * @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption
568
     * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions
569
     */
570
    public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfOptionsAreEmpty()
571
    {
572
        $stub = new ConnectionMandatoryRecursiveContainerIdConfiguration();
573
574
        $config = ['doctrine' => ['connection' => ['orm_default' => []]]];
575
576
        self::assertTrue($stub->canRetrieveOptions($config, 'orm_default'));
577
578
        $this->assertException(MandatoryOptionNotFoundException::class, 'Mandatory option "params"');
579
580
        $stub->options($config, 'orm_default');
581
    }
582
583
    /**
584
     * Returns test config
585
     *
586
     * @return array
587
     */
588
    private function getTestConfig()
589
    {
590
        // Load the user-defined test configuration file, if it exists; otherwise, load default
591
        if (is_readable('test/TestConfig.php')) {
592
            $testConfig = require 'test/testing.config.php';
593
        } else {
594
            $testConfig = require 'test/testing.config.php.dist';
595
        }
596
597
        return $testConfig;
598
    }
599
600
    /**
601
     * @param $exception
602
     * @param $message
603
     */
604
    private function assertException($exception, $message)
605
    {
606
        if (method_exists($this, 'expectException')) {
607
            $this->expectException($exception);
608
            $this->expectExceptionMessage($message);
609
        } else {
610
            $this->setExpectedException($exception, $message);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
611
        }
612
    }
613
}
614