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

ConfigTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 37
c 2
b 0
f 0
dl 0
loc 72
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testNoValidateConfigHasNoXsdValidation() 0 6 1
A testDefaultConfigHasXsdValidation() 0 5 1
A testDefaultConfigHasMessageFormats() 0 54 1
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