Completed
Push — master ( 341936...178071 )
by Florian
03:31
created

InstallmentPlanTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 24.36 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 19
loc 78
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 11 11 1
A testFormatPrice() 0 6 1
A testGetSelectLinkText() 0 13 1
A testGetPaymentInfoText() 0 8 1
A testGetDraftDownloadLink() 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 Magento\Sales\Model\Order;
30
use Payone\Core\Block\Payolution\InstallmentPlan as ClassToTest;
31
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
32
use Magento\Checkout\Model\Session;
33
use Magento\Framework\View\Element\Template\Context;
34
use Magento\Framework\UrlInterface;
35
use Payone\Core\Helper\Payment;
36
use Magento\Framework\Event\ManagerInterface;
37
use Magento\Framework\App\Config\ScopeConfigInterface;
38
39
class InstallmentPlanTest extends \PHPUnit_Framework_TestCase
40
{
41
    /**
42
     * @var ClassToTest
43
     */
44
    private $classToTest;
45
46
    /**
47
     * @var ObjectManager
48
     */
49
    private $objectManager;
50
51
    /**
52
     * @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
53
     */
54
    private $urlBuilder;
55
56
    /**
57
     * @var Session|\PHPUnit_Framework_MockObject_MockObject
58
     */
59
    private $checkoutSession;
0 ignored issues
show
Unused Code introduced by
The property $checkoutSession is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
60
61
    /**
62
     * @var Payment|\PHPUnit_Framework_MockObject_MockObject
63
     */
64
    private $paymentHelper;
0 ignored issues
show
Unused Code introduced by
The property $paymentHelper is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
65
66 View Code Duplication
    protected function setUp()
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...
67
    {
68
        $this->objectManager = new ObjectManager($this);
69
70
        $this->urlBuilder = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->getMock();
71
72
        $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
73
        $context->method('getUrlBuilder')->willReturn($this->urlBuilder);
74
75
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, ['context' => $context]);
76
    }
77
78
    public function testFormatPrice()
79
    {
80
        $result = $this->classToTest->formatPrice(50000.95);
81
        $expected = '50000,95';
82
        $this->assertEquals($expected, $result);
83
    }
84
85
    public function testGetSelectLinkText()
86
    {
87
        $aInstallment = [
88
            'currency' => 'EUR',
89
            'duration' => '12',
90
            'installment' => [
91
                '1' => ['amount' => 5]
92
            ]
93
        ];
94
        $expected = '5,00 EUR per month - 12 installments';
95
        $result = $this->classToTest->getSelectLinkText($aInstallment);
96
        $this->assertEquals($expected, $result);
97
    }
98
99
    public function testGetPaymentInfoText()
100
    {
101
        $aInstallment = ['currency' => 'EUR'];
102
        $aPayment = ['amount' => 10, 'due' => '01.01.2018'];
103
        $expected = '5. Installment: 10,00 EUR (due 01.01.2018)';
104
        $result = $this->classToTest->getPaymentInfoText(5, $aInstallment, $aPayment);
105
        $this->assertEquals($expected, $result);
106
    }
107
108 View Code Duplication
    public function testGetDraftDownloadLink()
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...
109
    {
110
        $expected = 'http://testdomain.com';
111
        $this->urlBuilder->method('getUrl')->willReturn($expected);
112
113
        $result = $this->classToTest->getDraftDownloadLink(5);
114
        $this->assertEquals($expected, $result);
115
    }
116
}
117