Completed
Pull Request — master (#144)
by
unknown
05:00
created

BaseTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 97
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 26 1
A testGetConfigParam() 0 14 1
A testGetConfigParamAllStores() 0 16 1
A testGetRequestParameter() 0 6 1
A testUnserialize() 0 6 1
A testSerialize() 0 6 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\Base;
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 Magento\Framework\App\Request\Http;
37
use Payone\Core\Test\Unit\BaseTestCase;
38
use Payone\Core\Test\Unit\PayoneObjectManager;
39
use Payone\Core\Helper\Shop;
40
41
class BaseTest extends BaseTestCase
42
{
43
    /**
44
     * @var ObjectManager|PayoneObjectManager
45
     */
46
    private $objectManager;
47
48
    /**
49
     * @var Base
50
     */
51
    private $base;
52
53
    /**
54
     * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
55
     */
56
    private $scopeConfig;
57
58
    protected function setUp()
59
    {
60
        $this->objectManager = $this->getObjectManager();
61
62
        $request = $this->getMockBuilder(Http::class)->disableOriginalConstructor()->getMock();
63
        $request->method('getParam')->willReturn('value');
64
65
        $this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
66
        $context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig, 'httpRequest' => $request]);
67
68
        $store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock();
69
        $store->method('getCode')->willReturn(null);
70
71
        $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock();
72
        $storeManager->method('getStore')->willReturn($store);
73
        $storeManager->method('getStores')->willReturn(['de' => $store, 'en' => $store, 'fr' => $store, 'nl' => $store]);
74
75
        $shopHelper = $this->getMockBuilder(Shop::class)->disableOriginalConstructor()->getMock();
76
        $shopHelper->method('getMagentoVersion')->willReturn('2.2.0');
77
78
        $this->base = $this->objectManager->getObject(Base::class, [
79
            'context' => $context,
80
            'storeManager' => $storeManager,
81
            'shopHelper' => $shopHelper
82
        ]);
83
    }
84
85
    public function testGetConfigParam()
86
    {
87
        $expected = 'authorization';
88
89
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
            ->method('getValue')
91
            ->willReturnMap(
92
                [
93
                    ['payone_general/global/request_type', ScopeInterface::SCOPE_STORE, null, $expected]
94
                ]
95
            );
96
        $result = $this->base->getConfigParam('request_type');
97
        $this->assertEquals($expected, $result);
98
    }
99
100
    public function testGetConfigParamAllStores()
101
    {
102
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
            ->method('getValue')
104
            ->willReturnMap(
105
                [
106
                    ['payone_general/global/mid', ScopeInterface::SCOPE_STORE, 'de', '12345'],
107
                    ['payone_general/global/mid', ScopeInterface::SCOPE_STORE, 'en', '23456'],
108
                    ['payone_general/global/mid', ScopeInterface::SCOPE_STORE, 'fr', '12345'],
109
                    ['payone_general/global/mid', ScopeInterface::SCOPE_STORE, 'nl', '34567'],
110
                ]
111
            );
112
        $result = $this->base->getConfigParamAllStores('mid');
113
        $expected = ['12345', '23456', '34567'];
114
        $this->assertEquals($expected, $result);
115
    }
116
117
    public function testGetRequestParameter()
118
    {
119
        $expected = 'value';
120
        $result = $this->base->getRequestParameter('param');
121
        $this->assertEquals($expected, $result);
122
    }
123
124
    public function testUnserialize()
125
    {
126
        $expected = ['test' => '123'];
127
        $result = $this->base->unserialize(json_encode($expected));
128
        $this->assertEquals($expected, $result);
129
    }
130
131
    public function testSerialize()
132
    {
133
        $input = ['test' => '123'];
134
        $result = $this->base->serialize($input);
135
        $this->assertEquals(json_encode($input), $result);
136
    }
137
}
138