ConfigProviderTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 78
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 4
dl 12
loc 78
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 39 1
A testGetConfig() 12 12 1
A testGetConfigNoInstance() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Model;
28
29
use Payone\Core\Model\ConfigProvider as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Payment\Helper\Data;
32
use Payone\Core\Helper\Country;
33
use Payone\Core\Helper\Customer;
34
use Payone\Core\Helper\Payment;
35
use Payone\Core\Helper\HostedIframe;
36
use Payone\Core\Helper\Request;
37
use Magento\Framework\Escaper;
38
use Payone\Core\Helper\Consumerscore;
39
use Payone\Core\Model\PayoneConfig;
40
use Magento\Payment\Model\Method\AbstractMethod;
41
use Payone\Core\Test\Unit\BaseTestCase;
42
use Payone\Core\Model\Test\PayoneObjectManager;
43
44
class ConfigProviderTest extends BaseTestCase
45
{
46
    /**
47
     * @var ClassToTest
48
     */
49
    private $classToTest;
50
51
    /**
52
     * @var ObjectManager|PayoneObjectManager
53
     */
54
    private $objectManager;
55
56
    /**
57
     * @var Data|\PHPUnit_Framework_MockObject_MockObject
58
     */
59
    private $dataHelper;
60
61
    protected function setUp()
62
    {
63
        $this->objectManager = $this->getObjectManager();
64
65
        $this->dataHelper = $this->getMockBuilder(Data::class)->disableOriginalConstructor()->getMock();
66
        $countryHelper = $this->getMockBuilder(Country::class)->disableOriginalConstructor()->getMock();
67
        $countryHelper->method('getDebitSepaCountries')->willReturn([['id' => 'DE', 'title' => 'Deutschland']]);
68
        $customerHelper = $this->getMockBuilder(Customer::class)->disableOriginalConstructor()->getMock();
69
        $customerHelper->method('customerHasGivenGender')->willReturn(true);
70
        $customerHelper->method('customerHasGivenBirthday')->willReturn(true);
71
        $paymentHelper = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock();
72
        $paymentHelper->method('getAvailableCreditcardTypes')->willReturn(['V', 'M']);
73
        $paymentHelper->method('isMandateManagementActive')->willReturn(true);
74
        $paymentHelper->method('isCheckCvcActive')->willReturn(true);
75
        $paymentHelper->method('getBankaccountCheckBlockedMessage')->willReturn('Computer says no');
76
        $paymentHelper->method('getAvailablePaymentTypes')->willReturn([PayoneConfig::METHOD_CREDITCARD]);
77
        $hostedIframeHelper = $this->getMockBuilder(HostedIframe::class)->disableOriginalConstructor()->getMock();
78
        $hostedIframeHelper->method('getHostedFieldConfig')->willReturn(['fields' => ['cvc' => ['width' => '20px']]]);
79
        $requestHelper = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
80
        $requestHelper->method('getHostedIframeRequest')->willReturn(['request' => 'creditcardcheck']);
81
        $requestHelper->method('getConfigParam')->willReturn('value');
82
        $requestHelper->method('getBankaccountCheckRequest')->willReturn(['request' => 'bankaccountcheck']);
83
        $escaper = $this->getMockBuilder(Escaper::class)->disableOriginalConstructor()->getMock();
84
        $escaper->method('escapeHtml')->willReturn('html');
85
        $consumerscoreHelper = $this->getMockBuilder(Consumerscore::class)->disableOriginalConstructor()->getMock();
86
        $consumerscoreHelper->method('canShowPaymentHintText')->willReturn(true);
87
        $consumerscoreHelper->method('canShowAgreementMessage')->willReturn(true);
88
89
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
90
            'dataHelper' => $this->dataHelper,
91
            'countryHelper' => $countryHelper,
92
            'customerHelper' => $customerHelper,
93
            'paymentHelper' => $paymentHelper,
94
            'hostedIframeHelper' => $hostedIframeHelper,
95
            'requestHelper' => $requestHelper,
96
            'escaper' => $escaper,
97
            'consumerscoreHelper' => $consumerscoreHelper
98
        ]);
99
    }
100
101 View Code Duplication
    public function testGetConfig()
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...
102
    {
103
        $method = $this->getMockBuilder(AbstractMethod::class)
104
            ->disableOriginalConstructor()
105
            ->setMethods(['getInstructions'])
106
            ->getMock();
107
        $method->method('getInstructions')->willReturn('Instruction');
108
        $this->dataHelper->method('getMethodInstance')->willReturn($method);
109
110
        $result = $this->classToTest->getConfig();
111
        $this->assertNotEmpty($result);
112
    }
113
114
    public function testGetConfigNoInstance()
115
    {
116
        $this->dataHelper->method('getMethodInstance')->willReturn(null);
117
118
        $result = $this->classToTest->getConfig();
119
        $this->assertNotEmpty($result);
120
    }
121
}
122