Completed
Push — master ( 7c1eaa...80d841 )
by Joachim
15:53
created

getEmptyConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.4285
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 testThrowsExceptionUnlessTerminalClassSet()
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['terminal_class']);
60
        $loader->load([$config], new ContainerBuilder());
61
    }
62
63 View Code Duplication
    public function testThrowsExceptionUnlessCallbackClassSet()
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['callback_class']);
70
        $loader->load([$config], new ContainerBuilder());
71
    }
72
73 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...
74
    {
75
        $this->expectException(InvalidConfigurationException::class);
76
77
        $loader = new LoevgaardDandomainAltapayExtension();
78
        $config = $this->getEmptyConfig();
79
        unset($config['altapay_ips']);
80
        $loader->load([$config], new ContainerBuilder());
81
    }
82
83
    public function testGettersSetters()
84
    {
85
        $loader = new LoevgaardDandomainAltapayExtension();
86
        $config = $this->getEmptyConfig();
87
        $container = new ContainerBuilder();
88
        $loader->load([$config], $container);
89
90
        $this->assertSame($config['altapay_username'], $container->getParameter('loevgaard_dandomain_altapay.altapay_username'));
91
        $this->assertSame($config['altapay_password'], $container->getParameter('loevgaard_dandomain_altapay.altapay_password'));
92
        $this->assertSame($config['altapay_ips'], $container->getParameter('loevgaard_dandomain_altapay.altapay_ips'));
93
        $this->assertSame($config['shared_key_1'], $container->getParameter('loevgaard_dandomain_altapay.shared_key_1'));
94
        $this->assertSame($config['shared_key_2'], $container->getParameter('loevgaard_dandomain_altapay.shared_key_2'));
95
        $this->assertSame($config['terminal_class'], $container->getParameter('loevgaard_dandomain_altapay.terminal_class'));
96
        $this->assertSame($config['callback_class'], $container->getParameter('loevgaard_dandomain_altapay.callback_class'));
97
        $this->assertSame($config['http_transaction_class'], $container->getParameter('loevgaard_dandomain_altapay.http_transaction_class'));
98
        $this->assertSame($config['payment_class'], $container->getParameter('loevgaard_dandomain_altapay.payment_class'));
99
        $this->assertSame($config['payment_line_class'], $container->getParameter('loevgaard_dandomain_altapay.payment_line_class'));
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    protected function getEmptyConfig()
106
    {
107
        $yaml = <<<EOF
108
altapay_username: username
109
altapay_password: password
110
altapay_ips: ['123.123.123.123']
111
shared_key_1: key1
112
shared_key_2: key2
113
terminal_class: TerminalClass
114
callback_class: CallbackClass
115
http_transaction_class: HttpTransactionClass
116
payment_class: PaymentClass
117
payment_line_class: PaymentLineClass
118
EOF;
119
        $parser = new Parser();
120
121
        return $parser->parse($yaml);
122
    }
123
}
124