ConfigExportTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 162
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 162
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 38 1
A testGetModuleInfo() 0 9 1
A testGetPaymentConfigNonGlobal() 0 17 1
A testGetPaymentConfigGlobal() 0 16 1
B testGetCountries() 0 29 1
A testGetForwardings() 0 9 1
A testGetMappings() 0 15 1
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2017 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Test\Unit\Helper;
28
29
use Payone\Core\Helper\ConfigExport;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Store\Model\StoreManagerInterface;
32
use Magento\Store\Api\Data\StoreInterface;
33
use Magento\Framework\App\Helper\Context;
34
use Magento\Store\Model\ScopeInterface;
35
use Magento\Framework\App\Config\ScopeConfigInterface;
36
use Payone\Core\Helper\Database;
37
use Payone\Core\Helper\Config;
38
use Payone\Core\Helper\Payment;
39
use Payone\Core\Helper\Toolkit;
40
use Payone\Core\Test\Unit\BaseTestCase;
41
use Payone\Core\Model\Test\PayoneObjectManager;
42
43
class ConfigExportTest extends BaseTestCase
44
{
45
    /**
46
     * @var ObjectManager|PayoneObjectManager
47
     */
48
    private $objectManager;
49
50
    /**
51
     * @var ConfigExport
52
     */
53
    private $configExport;
54
55
    /**
56
     * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
57
     */
58
    private $scopeConfig;
59
60
    /**
61
     * @var Toolkit
62
     */
63
    private $toolkitHelper;
64
65
    protected function setUp()
66
    {
67
        $this->objectManager = $this->getObjectManager();
68
69
        $this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
70
        $context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]);
71
72
        $store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock();
73
        $store->method('getCode')->willReturn(null);
74
75
        $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock();
76
        $storeManager->method('getStore')->willReturn($store);
77
78
        $databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock();
79
        $databaseHelper->method('getModuleInfo')->willReturn([
80
            ['module' => 'Payone_Core', 'schema_version' => '1.3.1'],
81
            ['module' => 'Another_Module', 'schema_version' => '2.3.4']
82
        ]);
83
84
        $configHelper = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
85
        $configHelper->method('getForwardingUrls')->willReturn([
86
            ['txaction' => ['appointed', 'pending'], 'url' => 'http://forward.to', 'timeout' => 15],
87
            ['txaction' => ['paid'], 'url' => 'http://forward.to', 'timeout' => null]
88
        ]);
89
90
        $paymentHelper = $this->objectManager->getObject(Payment::class);
91
92
        $this->toolkitHelper = $this->objectManager->getObject(Toolkit::class);
93
94
        $this->configExport = $this->objectManager->getObject(ConfigExport::class, [
95
            'context' => $context,
96
            'storeManager' => $storeManager,
97
            'paymentHelper' => $paymentHelper,
98
            'databaseHelper' => $databaseHelper,
99
            'configHelper' => $configHelper,
100
            'toolkitHelper' => $this->toolkitHelper
101
        ]);
102
    }
103
104
    public function testGetModuleInfo()
105
    {
106
        $result = $this->configExport->getModuleInfo();
107
        $expected = [
108
            'Payone_Core' => '1.3.1',
109
            'Another_Module' => '2.3.4'
110
        ];
111
        $this->assertEquals($expected, $result);
112
    }
113
114
    public function testGetPaymentConfigNonGlobal()
115
    {
116
        $expected = '12345';
117
118
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
119
            ->method('getValue')
120
            ->willReturnMap(
121
                [
122
                    ['payone_payment/payone_creditcard/use_global', ScopeInterface::SCOPE_STORE, null, 0],
123
                    ['payone_payment/payone_creditcard/mid', ScopeInterface::SCOPE_STORE, null, $expected]
124
                ]
125
            );
126
        $result = $this->configExport->getPaymentConfig('mid', 'payone_creditcard', null, false);
127
        $this->assertEquals($expected, $result);
128
        $result = $this->configExport->getPaymentConfig('mid', 'payone_creditcard', null, true);
129
        $this->assertEquals($expected, $result);
130
    }
131
132
    public function testGetPaymentConfigGlobal()
133
    {
134
        $expected = '12345';
135
136
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
137
            ->method('getValue')
138
            ->willReturnMap(
139
                [
140
                    ['payone_payment/payone_creditcard/use_global', ScopeInterface::SCOPE_STORE, null, 1],
141
                    ['payone_payment/payone_creditcard/mid', ScopeInterface::SCOPE_STORE, null, 'random_mid'],
142
                    ['payone_general/global/mid', ScopeInterface::SCOPE_STORE, null, $expected]
143
                ]
144
            );
145
        $result = $this->configExport->getPaymentConfig('mid', 'payone_creditcard', null, true);
146
        $this->assertEquals($expected, $result);
147
    }
148
149
    public function testGetCountries()
150
    {
151
        $expected = 'DE,FR,NL';
152
153
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
154
            ->method('getValue')
155
            ->willReturnMap(
156
                [
157
                    ['payone_payment/payone_creditcard/use_global', ScopeInterface::SCOPE_STORE, null, 0],
158
                    ['payone_payment/payone_creditcard/allowspecific', ScopeInterface::SCOPE_STORE, null, 1],
159
                    ['payone_payment/payone_creditcard/specificcountry', ScopeInterface::SCOPE_STORE, null, $expected],
160
                    ['payone_payment/payone_invoice/use_global', ScopeInterface::SCOPE_STORE, null, 1],
161
                    ['payone_general/global/allowspecific', ScopeInterface::SCOPE_STORE, null, 1],
162
                    ['payone_general/global/specificcountry', ScopeInterface::SCOPE_STORE, null, $expected],
163
                    ['payone_payment/payone_paypal/use_global', ScopeInterface::SCOPE_STORE, null, 0],
164
                    ['payone_general/payone_paypal/allowspecific', ScopeInterface::SCOPE_STORE, null, 0]
165
                ]
166
            );
167
168
        $result = $this->configExport->getCountries('payone_creditcard', null);
169
        $this->assertEquals($expected, $result);
170
171
        $result = $this->configExport->getCountries('payone_invoice', null);
172
        $this->assertEquals($expected, $result);
173
174
        $result = $this->configExport->getCountries('payone_paypal', null);
175
        $expected = '';
176
        $this->assertEquals($expected, $result);
177
    }
178
179
    public function testGetForwardings()
180
    {
181
        $result = $this->configExport->getForwardings(null);
182
        $expected = [
183
            ['status' => 'appointed,pending', 'url' => 'http://forward.to', 'timeout' => 15],
184
            ['status' => 'paid', 'url' => 'http://forward.to', 'timeout' => 0],
185
        ];
186
        $this->assertEquals($expected, $result);
187
    }
188
189
    public function testGetMappings()
190
    {
191
        $config = ['random' => ['txaction' => 'appointed', 'state_status' => 'processing']];
192
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
193
            ->method('getValue')
194
            ->willReturnMap(
195
                [
196
                    ['payone_general/statusmapping/payone_creditcard', ScopeInterface::SCOPE_STORE, null, $this->toolkitHelper->serialize($config)]
197
                ]
198
            );
199
200
        $result = $this->configExport->getMappings(null);
201
        $expected = ['cc' => [['from' => 'appointed', 'to' => 'processing']]];
202
        $this->assertEquals($result, $expected);
203
    }
204
}
205