Passed
Pull Request — master (#111)
by Andreas
19:08
created

ConfigTest::testDefaultConfigHasMessageFormats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 31
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 54
rs 9.424

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Genkgo\TestCamt\Unit;
6
7
use Genkgo\Camt\Camt052;
8
use Genkgo\Camt\Camt053;
9
use Genkgo\Camt\Camt054;
10
use Genkgo\Camt\Config;
11
use Genkgo\Camt\MessageFormatInterface;
12
use PHPUnit\Framework\TestCase;
13
14
/**
15
 * @group config
16
 */
17
class ConfigTest extends TestCase
18
{
19
    public function testDefaultConfigHasMessageFormats(): void
20
    {
21
        $config = Config::getDefault();
22
23
        $messageFormats = $config->getMessageFormats();
24
25
        $expectedMessageFormats = [
26
            Camt052\MessageFormat\V01::class,
27
            Camt052\MessageFormat\V02::class,
28
            Camt052\MessageFormat\V04::class,
29
            Camt052\MessageFormat\V06::class,
30
            Camt053\MessageFormat\V02::class,
31
            Camt053\MessageFormat\V03::class,
32
            Camt053\MessageFormat\V04::class,
33
            Camt054\MessageFormat\V02::class,
34
            Camt054\MessageFormat\V04::class,
35
        ];
36
37
        $actualMessageFormats = array_map(static function (MessageFormatInterface $messageFormat): string {
38
            return get_class($messageFormat);
39
        }, $messageFormats);
40
41
        $additionalMessageFormats = array_diff(
42
            $actualMessageFormats,
43
            $expectedMessageFormats
44
        );
45
46
        self::assertEmpty($additionalMessageFormats, sprintf(
47
            <<<TXT
48
Failed asserting that the default configuration does not configure additional message formats. 
49
50
Did you intend to add the following message formats?
51
52
- %s
53
54
TXT,
55
            implode("\n- ", $additionalMessageFormats)
56
        ));
57
58
        $missingMessageFormats = array_diff(
59
            $expectedMessageFormats,
60
            $actualMessageFormats
61
        );
62
63
        self::assertEmpty($missingMessageFormats, sprintf(
64
            <<<TXT
65
Failed asserting that the default configuration configures all expected formats. 
66
67
Have you forgotten to add the following message formats?
68
69
- %s
70
71
TXT,
72
            implode("\n- ", $missingMessageFormats)
73
        ));
74
    }
75
76
    public function testDefaultConfigHasXsdValidation(): void
77
    {
78
        $config = Config::getDefault();
79
80
        self::assertTrue($config->getXsdValidation());
81
    }
82
83
    public function testNoValidateConfigHasNoXsdValidation(): void
84
    {
85
        $config = Config::getDefault();
86
        $config->disableXsdValidation();
87
88
        self::assertFalse($config->getXsdValidation());
89
    }
90
}
91