testThrowsExceptionUnlessSharedKey1Set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
c 0
b 0
f 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Tests\DependencyInjection;
4
5
use Loevgaard\DandomainAltapayBundle\DependencyInjection\LoevgaardDandomainAltapayExtension;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\Yaml\Parser;
10
11
class LoevgaardDandomainAltapayExtensionTest extends TestCase
12
{
13 View Code Duplication
    public function testThrowsExceptionUnlessAltapayUsernameSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        $this->expectException(InvalidConfigurationException::class);
16
17
        $loader = new LoevgaardDandomainAltapayExtension();
18
        $config = $this->getEmptyConfig();
19
        unset($config['altapay_username']);
20
        $loader->load([$config], new ContainerBuilder());
21
    }
22
23 View Code Duplication
    public function testThrowsExceptionUnlessAltapayPasswordSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $this->expectException(InvalidConfigurationException::class);
26
27
        $loader = new LoevgaardDandomainAltapayExtension();
28
        $config = $this->getEmptyConfig();
29
        unset($config['altapay_password']);
30
        $loader->load([$config], new ContainerBuilder());
31
    }
32
33 View Code Duplication
    public function testThrowsExceptionUnlessSharedKey1Set()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $this->expectException(InvalidConfigurationException::class);
36
37
        $loader = new LoevgaardDandomainAltapayExtension();
38
        $config = $this->getEmptyConfig();
39
        unset($config['shared_key_1']);
40
        $loader->load([$config], new ContainerBuilder());
41
    }
42
43 View Code Duplication
    public function testThrowsExceptionUnlessSharedKey2Set()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $this->expectException(InvalidConfigurationException::class);
46
47
        $loader = new LoevgaardDandomainAltapayExtension();
48
        $config = $this->getEmptyConfig();
49
        unset($config['shared_key_2']);
50
        $loader->load([$config], new ContainerBuilder());
51
    }
52
53 View Code Duplication
    public function testThrowsExceptionUnlessAltapayIpsSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $this->expectException(InvalidConfigurationException::class);
56
57
        $loader = new LoevgaardDandomainAltapayExtension();
58
        $config = $this->getEmptyConfig();
59
        unset($config['altapay_ips']);
60
        $loader->load([$config], new ContainerBuilder());
61
    }
62
63 View Code Duplication
    public function testThrowsExceptionUnlessDefaultSettingsSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $this->expectException(InvalidConfigurationException::class);
66
67
        $loader = new LoevgaardDandomainAltapayExtension();
68
        $config = $this->getEmptyConfig();
69
        unset($config['default_settings']);
70
        $loader->load([$config], new ContainerBuilder());
71
    }
72
73
    public function testGettersSetters()
74
    {
75
        $loader = new LoevgaardDandomainAltapayExtension();
76
        $config = $this->getEmptyConfig();
77
        $container = new ContainerBuilder();
78
        $loader->load([$config], $container);
79
80
        $this->assertSame($config['altapay_username'], $container->getParameter('loevgaard_dandomain_altapay.altapay_username'));
81
        $this->assertSame($config['altapay_password'], $container->getParameter('loevgaard_dandomain_altapay.altapay_password'));
82
        $this->assertSame($config['altapay_url'], $container->getParameter('loevgaard_dandomain_altapay.altapay_url'));
83
        $this->assertSame($config['altapay_ips'], $container->getParameter('loevgaard_dandomain_altapay.altapay_ips'));
84
        $this->assertSame($config['shared_key_1'], $container->getParameter('loevgaard_dandomain_altapay.shared_key_1'));
85
        $this->assertSame($config['shared_key_2'], $container->getParameter('loevgaard_dandomain_altapay.shared_key_2'));
86
        $this->assertSame($config['webhook_urls'], $container->getParameter('loevgaard_dandomain_altapay.webhook_urls'));
87
        $this->assertSame($config['default_settings'], $container->getParameter('loevgaard_dandomain_altapay.default_settings'));
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    protected function getEmptyConfig()
94
    {
95
        $yaml = <<<EOF
96
altapay_username: username
97
altapay_password: password
98
altapay_url: https://altapayurl.com
99
altapay_ips: ['123.123.123.123']
100
shared_key_1: key1
101
shared_key_2: key2
102
webhook_urls:
103
    ['http://www.example.com']
104
default_settings:
105
    layout:
106
        logo: logo_default.jpg
107
    opening_days: Monday - Friday
108
    opening_hours: 09:00 - 15:00
109
    email: [email protected]
110
    phone: +45 11 22 33 44
111
EOF;
112
        $parser = new Parser();
113
114
        return $parser->parse($yaml);
115
    }
116
}
117