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

MethodListTest::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 38
rs 8.8571
cc 1
eloc 28
nc 1
nop 0
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\Plugins;
28
29
use Payone\Core\Model\PayoneConfig;
30
use Payone\Core\Model\Plugins\MethodList as ClassToTest;
31
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
32
use Magento\Payment\Model\MethodList;
33
use Payone\Core\Model\Api\Request\Consumerscore;
34
use Payone\Core\Helper\Consumerscore as ConsumerscoreHelper;
35
use Magento\Checkout\Model\Session;
36
use Magento\Quote\Model\Quote;
37
use Magento\Quote\Model\Quote\Address;
38
use Magento\Payment\Model\MethodInterface;
39
40
class MethodListTest extends \PHPUnit_Framework_TestCase
41
{
42
    /**
43
     * @var ClassToTest
44
     */
45
    private $classToTest;
46
47
    /**
48
     * @var ObjectManager
49
     */
50
    private $objectManager;
51
52
    /**
53
     * @var Consumerscore|\PHPUnit_Framework_MockObject_MockObject
54
     */
55
    private $consumerscore;
56
57
    /**
58
     * @var ConsumerscoreHelper|\PHPUnit_Framework_MockObject_MockObject
59
     */
60
    private $consumerscoreHelper;
61
62
    protected function setUp()
63
    {
64
        $this->objectManager = new ObjectManager($this);
65
66
        $this->consumerscore = $this->getMockBuilder(Consumerscore::class)->disableOriginalConstructor()->getMock();
67
        $this->consumerscoreHelper = $this->getMockBuilder(ConsumerscoreHelper::class)->disableOriginalConstructor()->getMock();
68
        $this->consumerscoreHelper->method('isCreditratingNeeded')->willReturn(true);
69
        $this->consumerscoreHelper->method('getConfigParam')->willReturn(true);
70
        $this->consumerscoreHelper->expects($this->any())
71
            ->method('getAllowedMethodsForScore')
72
            ->willReturnMap([
73
                    ['Y', [PayoneConfig::METHOD_CREDITCARD, PayoneConfig::METHOD_ADVANCE_PAYMENT]],
74
                    ['R', [PayoneConfig::METHOD_DEBIT, PayoneConfig::METHOD_CASH_ON_DELIVERY]]
75
                ]);
76
77
78
        $address = $this->getMockBuilder(Address::class)
79
            ->disableOriginalConstructor()
80
            ->setMethods(['getPayoneAddresscheckScore', 'setPayoneProtectScore', 'getPayoneProtectScore', 'save'])
81
            ->getMock();
82
        $address->method('getPayoneAddresscheckScore')->willReturn('Y');
83
        $address->method('getPayoneProtectScore')->willReturn('Y');
84
        $address->method('setPayoneProtectScore')->willReturn($address);
85
        $address->method('save')->willReturn($address);
86
87
        $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock();
88
        $quote->method('getShippingAddress')->willReturn($address);
89
        $quote->method('getGrandTotal')->willReturn(100.00);
90
91
        $checkoutSession = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
92
        $checkoutSession->method('getQuote')->willReturn($quote);
93
94
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
95
            'consumerscore' => $this->consumerscore,
96
            'consumerscoreHelper' => $this->consumerscoreHelper,
97
            'checkoutSession' => $checkoutSession
98
        ]);
99
    }
100
101
    public function testAfterGetAvailableMethodsPreviousCheck()
102
    {
103
        $this->consumerscore->method('sendRequest')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Payone\Core\Model...\Request\Consumerscore>.

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...
104
        $this->consumerscoreHelper->method('getWorstScore')->willReturn('Y');
0 ignored issues
show
Bug introduced by
The method method() does not exist on Payone\Core\Helper\Consumerscore. Did you maybe mean getAllowedMethodsForScore()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
105
106
        $subject = $this->getMockBuilder(MethodList::class)->disableOriginalConstructor()->getMock();
107
108
        $payment = $this->getMockBuilder(MethodInterface::class)->disableOriginalConstructor()->getMock();
109
        $payment->method('getCode')->willReturn(PayoneConfig::METHOD_DEBIT);
110
        $paymentMethods = [$payment];
111
112
        $result = $this->classToTest->afterGetAvailableMethods($subject, $paymentMethods);
113
        $this->assertInstanceOf(MethodInterface::class, $result[0]);
114
    }
115
116 View Code Duplication
    public function testAfterGetAvailableMethods()
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...
117
    {
118
        $this->consumerscore->method('sendRequest')->willReturn(['score' => 'Y']);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Payone\Core\Model...\Request\Consumerscore>.

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
        $this->consumerscoreHelper->method('getWorstScore')->willReturn('R');
0 ignored issues
show
Bug introduced by
The method method() does not exist on Payone\Core\Helper\Consumerscore. Did you maybe mean getAllowedMethodsForScore()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
120
121
        $subject = $this->getMockBuilder(MethodList::class)->disableOriginalConstructor()->getMock();
122
123
        $payment = $this->getMockBuilder(MethodInterface::class)->disableOriginalConstructor()->getMock();
124
        $payment->method('getCode')->willReturn(PayoneConfig::METHOD_CASH_ON_DELIVERY);
125
        $paymentMethods = [$payment];
126
127
        $result = $this->classToTest->afterGetAvailableMethods($subject, $paymentMethods);
128
        $this->assertInstanceOf(MethodInterface::class, $result[0]);
129
    }
130
131 View Code Duplication
    public function testAfterGetAvailableMethodsEmpty()
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...
132
    {
133
        $this->consumerscore->method('sendRequest')->willReturn(['score' => 'Y']);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Payone\Core\Model...\Request\Consumerscore>.

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...
134
        $this->consumerscoreHelper->method('getWorstScore')->willReturn('R');
0 ignored issues
show
Bug introduced by
The method method() does not exist on Payone\Core\Helper\Consumerscore. Did you maybe mean getAllowedMethodsForScore()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
135
136
        $subject = $this->getMockBuilder(MethodList::class)->disableOriginalConstructor()->getMock();
137
138
        $payment = $this->getMockBuilder(MethodInterface::class)->disableOriginalConstructor()->getMock();
139
        $payment->method('getCode')->willReturn(PayoneConfig::METHOD_BARZAHLEN);
140
        $paymentMethods = [$payment];
141
142
        $result = $this->classToTest->afterGetAvailableMethods($subject, $paymentMethods);
143
        $this->assertEmpty($result);
144
    }
145
}
146