Completed
Push — master ( ea4e5e...1a7580 )
by Zbigniew
02:25
created

ConfigurationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 12
loc 52
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of the WrikeBundle package.
4
 *
5
 * (c) Zbigniew Ślązak
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zibios\Bundle\WrikeBundle\Tests\DependencyInjection;
12
13
use Zibios\Bundle\WrikeBundle\DependencyInjection\Configuration;
14
use Symfony\Component\Config\Definition\Processor;
15
16
/**
17
 * ConfigurationTest
18
 */
19
class ConfigurationTest extends DependencyInjectionTestCase
20
{
21
    /**
22
     * Some basic tests to make sure the configuration is correctly processed in the standard case.
23
     *
24
     * @param array $sourceConfig
25
     * @param array $expectedConfig
26
     * @param $expectedExceptionClass
27
     *
28
     * @dataProvider configurationProvider
29
     */
30
    public function testProcessConfig(array $sourceConfig, array $expectedConfig, $expectedExceptionClass)
31
    {
32
        $processor = new Processor();
33
34
        $exceptionOccurred = false;
35
        $exceptionClass = '';
36
        $exceptionMessage = '';
37
        $calculatedConfig = [];
38
        try {
39
            $calculatedConfig = $processor->processConfiguration(new Configuration(), [$sourceConfig]);
40
        } catch (\Exception $e) {
41
            $exceptionOccurred = true;
42
            $exceptionClass = get_class($e);
43
            $exceptionMessage = $e->getMessage();
44
        }
45
46
        if ($expectedExceptionClass !== false) {
47
            self::assertTrue(
48
                $exceptionOccurred,
49
                sprintf(
50
                    '"%s" exception should occurred for "%s".',
51
                    $expectedExceptionClass,
52
                    json_encode($sourceConfig)
53
                )
54
            );
55
        }
56
57
        if ($expectedExceptionClass === false) {
58
            self::assertFalse(
59
                $exceptionOccurred,
60
                sprintf(
61
                    '"%s" exception occurred but should not for "%s". Message "%s"',
62
                    $exceptionClass,
63
                    json_encode($sourceConfig),
64
                    $exceptionMessage
65
                )
66
            );
67
            $this->assertEquals($expectedConfig, $calculatedConfig);
68
        }
69
    }
70
}
71