Completed
Push — master ( fe4d16...77dac1 )
by Florian
26:03
created

DebitTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 24.49 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 2
dl 24
loc 98
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 19 1
A testGetMandateText() 0 12 1
A testGetMandateTextFalse() 0 7 1
A testGetMandateId() 8 8 1
A testGetMandateIdFalse() 0 7 1
A testGetCheckoutUrl() 8 8 1
A testGetErrorMessage() 8 8 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\Block\Onepage;
28
29
use Payone\Core\Block\Onepage\Debit as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Checkout\Model\Session;
32
use Magento\Framework\View\Element\Template\Context;
33
use Magento\Framework\UrlInterface;
34
35
class DebitTest extends \PHPUnit_Framework_TestCase
36
{
37
    /**
38
     * @var ClassToTest
39
     */
40
    private $classToTest;
41
42
    /**
43
     * @var ObjectManager
44
     */
45
    private $objectManager;
46
47
    /**
48
     * @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
49
     */
50
    private $urlBuilder;
51
52
    /**
53
     * @var Session|\PHPUnit_Framework_MockObject_MockObject
54
     */
55
    private $checkoutSession;
56
57
    protected function setUp()
58
    {
59
        $this->objectManager = new ObjectManager($this);
60
61
        $this->urlBuilder = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->getMock();
62
63
        $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
64
        $context->method('getUrlBuilder')->willReturn($this->urlBuilder);
65
66
        $this->checkoutSession = $this->getMockBuilder(Session::class)
67
            ->disableOriginalConstructor()
68
            ->setMethods(['getPayoneMandate', 'getPayoneDebitError', 'unsPayoneDebitError'])
69
            ->getMock();
70
71
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
72
            'context' => $context,
73
            'checkoutSession' => $this->checkoutSession
74
        ]);
75
    }
76
77
    public function testGetMandateText()
78
    {
79
        $expected = 'test text';
80
81
        $this->checkoutSession->method('getPayoneMandate')->willReturn([
82
            'mandate_status' => 'pending',
83
            'mandate_text' => urlencode($expected)
84
        ]);
85
86
        $result = $this->classToTest->getMandateText();
87
        $this->assertEquals($expected, $result);
88
    }
89
90
    public function testGetMandateTextFalse()
91
    {
92
        $this->checkoutSession->method('getPayoneMandate')->willReturn(false);
93
94
        $result = $this->classToTest->getMandateText();
95
        $this->assertFalse($result);
96
    }
97
98 View Code Duplication
    public function testGetMandateId()
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...
99
    {
100
        $expected = '12345';
101
        $this->checkoutSession->method('getPayoneMandate')->willReturn(['mandate_identification' => $expected]);
102
103
        $result = $this->classToTest->getMandateId();
104
        $this->assertEquals($expected, $result);
105
    }
106
107
    public function testGetMandateIdFalse()
108
    {
109
        $this->checkoutSession->method('getPayoneMandate')->willReturn(false);
110
111
        $result = $this->classToTest->getMandateId();
112
        $this->assertFalse($result);
113
    }
114
115 View Code Duplication
    public function testGetCheckoutUrl()
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...
116
    {
117
        $expected = 'http://testdomain.com';
118
        $this->urlBuilder->method('getUrl')->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\UrlInterface>.

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...
119
120
        $result = $this->classToTest->getCheckoutUrl();
121
        $this->assertEquals($expected, $result);
122
    }
123
124 View Code Duplication
    public function testGetErrorMessage()
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...
125
    {
126
        $expected = 'An error occured';
127
        $this->checkoutSession->method('getPayoneDebitError')->willReturn($expected);
128
129
        $result = $this->classToTest->getErrorMessage();
130
        $this->assertEquals($expected, $result);
131
    }
132
}
133