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

InstallmentPlanTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 38 1
B testGetInstallmentPlan() 0 29 1
A testGetInstallmentPlanErrorPre() 0 8 1
A testGetInstallmentPlanErrorCalc() 0 11 1
A testGetInstallmentPlanErrorUnknown() 0 7 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\Service\V1\Data;
28
29
use Payone\Core\Service\V1\InstallmentPlan as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Payone\Core\Service\V1\Data\InstallmentPlanResponse;
32
use Payone\Core\Api\Data\InstallmentPlanResponseInterfaceFactory;
33
use Magento\Checkout\Model\Session;
34
use Magento\Quote\Model\Quote;
35
use Payone\Core\Model\Api\Request\Genericpayment\PreCheck;
36
use Payone\Core\Model\Api\Request\Genericpayment\Calculation;
37
use Payone\Core\Block\Payolution\InstallmentPlan;
38
39
class InstallmentPlanTest extends \PHPUnit_Framework_TestCase
40
{
41
    /**
42
     * @var ClassToTest
43
     */
44
    private $classToTest;
45
46
    /**
47
     * @var InstallmentPlanResponse|\PHPUnit_Framework_MockObject_MockObject
48
     */
49
    private $response;
50
51
    /**
52
     * @var PreCheck|\PHPUnit_Framework_MockObject_MockObject
53
     */
54
    private $precheck;
55
56
    /**
57
     * @var Calculation|\PHPUnit_Framework_MockObject_MockObject
58
     */
59
    private $calculation;
60
61
    protected function setUp()
62
    {
63
        $objectManager = new ObjectManager($this);
64
65
        $this->response = $objectManager->getObject(InstallmentPlanResponse::class);
66
        #$responseFactory = $objectManager->getObject(InstallmentPlanResponseFactory::class);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
        $responseFactory = $this->getMockBuilder(InstallmentPlanResponseInterfaceFactory::class)
68
            ->disableOriginalConstructor()
69
            ->setMethods(['create'])
70
            ->getMock();
71
        $responseFactory->method('create')->willReturn($this->response);
72
73
        $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock();
74
        $quote->method('getBaseGrandTotal')->willReturn(100);
75
76
        $checkoutSession = $this->getMockBuilder(Session::class)
77
            ->disableOriginalConstructor()
78
            ->setMethods(['setInstallmentDraftLinks', 'setInstallmentWorkorderId', 'getQuote'])
79
            ->getMock();
80
        $checkoutSession->method('getQuote')->willReturn($quote);
81
82
        $this->precheck = $this->getMockBuilder(PreCheck::class)->disableOriginalConstructor()->getMock();
83
        $this->calculation = $this->getMockBuilder(Calculation::class)->disableOriginalConstructor()->getMock();
84
85
        $block = $this->getMockBuilder(InstallmentPlan::class)
86
            ->disableOriginalConstructor()
87
            ->setMethods(['setInstallmentData', 'setCode', 'toHtml'])
88
            ->getMock();
89
        $block->method('toHtml')->willReturn('InstallmentPlanHtml');
90
91
        $this->classToTest = $objectManager->getObject(ClassToTest::class, [
92
            'responseFactory' => $responseFactory,
93
            'checkoutSession' => $checkoutSession,
94
            'precheck' => $this->precheck,
95
            'calculation' => $this->calculation,
96
            'block' => $block
97
        ]);
98
    }
99
100
    public function testGetInstallmentPlan()
101
    {
102
        $precheck = ['status' => 'OK'];
103
        $this->precheck->method('sendRequest')->willReturn($precheck);
104
105
        $calculation = [
106
            'status' => 'OK',
107
            'workorderid' => 'WORKORDERID',
108
            'add_paydata[PaymentDetails_1_Duration]' => '3',
109
            'add_paydata[PaymentDetails_1_MinimumInstallmentFee]' => '0',
110
            'add_paydata[PaymentDetails_1_InterestRate]' => '14.95',
111
            'add_paydata[PaymentDetails_1_Usage]' => 'Calculated by calculation service',
112
            'add_paydata[PaymentDetails_1_EffectiveInterestRate]' => '16.03',
113
            'add_paydata[PaymentDetails_1_TotalAmount]' => '1278.09',
114
            'add_paydata[PaymentDetails_1_OriginalAmount]' => '1249.50',
115
            'add_paydata[PaymentDetails_1_Currency]' => 'EUR',
116
            'add_paydata[PaymentDetails_1_StandardCreditInformationUrl]' => 'http://installmentdraft.test',
117
            'add_paydata[PaymentDetails_1_Installment_1_Amount]' => '426.03',
118
            'add_paydata[PaymentDetails_1_Installment_1_Due]' => '2017-08-20',
119
            'add_paydata[PaymentDetails_1_Installment_2_Amount]' => '426.03',
120
            'add_paydata[PaymentDetails_1_Installment_2_Due]' => '2017-09-20',
121
            'add_paydata[PaymentDetails_1_Installment_3_Amount]' => '426.03',
122
            'add_paydata[PaymentDetails_1_Installment_3_Due]' => '2017-10-20',
123
        ];
124
        $this->calculation->method('sendRequest')->willReturn($calculation);
125
126
        $result = $this->classToTest->getInstallmentPlan('19900909');
127
        $this->assertTrue($result->getSuccess());
128
    }
129
130
    public function testGetInstallmentPlanErrorPre()
131
    {
132
        $precheck = ['status' => 'ERROR', 'errorcode' => '123', 'customermessage' => 'error'];
133
        $this->precheck->method('sendRequest')->willReturn($precheck);
134
135
        $result = $this->classToTest->getInstallmentPlan('19900909');
136
        $this->assertFalse($result->getSuccess());
137
    }
138
139
    public function testGetInstallmentPlanErrorCalc()
140
    {
141
        $precheck = ['status' => 'OK'];
142
        $this->precheck->method('sendRequest')->willReturn($precheck);
143
144
        $calculation = ['status' => 'ERROR', 'errorcode' => '123', 'customermessage' => 'error'];
145
        $this->calculation->method('sendRequest')->willReturn($calculation);
146
147
        $result = $this->classToTest->getInstallmentPlan('19900909');
148
        $this->assertFalse($result->getSuccess());
149
    }
150
151
    public function testGetInstallmentPlanErrorUnknown()
152
    {
153
        $this->precheck->method('sendRequest')->willReturn(false);
154
155
        $result = $this->classToTest->getInstallmentPlan('19900909');
156
        $this->assertFalse($result->getSuccess());
157
    }
158
}
159