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\Api\Request\Genericpayment; |
28
|
|
|
|
29
|
|
|
use Magento\Quote\Model\Quote; |
30
|
|
|
use Payone\Core\Model\Api\Request\Genericpayment\Calculation as ClassToTest; |
31
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
32
|
|
|
use Payone\Core\Helper\Api; |
33
|
|
|
use Payone\Core\Helper\Shop; |
34
|
|
|
use Payone\Core\Model\Methods\Paypal; |
35
|
|
|
use Magento\Quote\Model\Quote\Address; |
36
|
|
|
use Payone\Core\Test\Unit\BaseTestCase; |
37
|
|
|
use Payone\Core\Model\Test\PayoneObjectManager; |
38
|
|
|
|
39
|
|
|
class CalculationTest extends BaseTestCase |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var ClassToTest |
43
|
|
|
*/ |
44
|
|
|
private $classToTest; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var Api|\PHPUnit_Framework_MockObject_MockObject |
48
|
|
|
*/ |
49
|
|
|
private $apiHelper; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var Shop|\PHPUnit_Framework_MockObject_MockObject |
53
|
|
|
*/ |
54
|
|
|
private $shopHelper; |
55
|
|
|
|
56
|
|
View Code Duplication |
protected function setUp() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$objectManager = $this->getObjectManager(); |
59
|
|
|
|
60
|
|
|
$this->apiHelper = $this->getMockBuilder(Api::class)->disableOriginalConstructor()->getMock(); |
61
|
|
|
$this->shopHelper = $this->getMockBuilder(Shop::class)->disableOriginalConstructor()->getMock(); |
62
|
|
|
|
63
|
|
|
$this->classToTest = $objectManager->getObject(ClassToTest::class, [ |
64
|
|
|
'shopHelper' => $this->shopHelper, |
65
|
|
|
'apiHelper' => $this->apiHelper |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testSendRequest() |
70
|
|
|
{ |
71
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
72
|
|
|
$address->method('getCountryId')->willReturn('DE'); |
73
|
|
|
$address->method('getLastname')->willReturn('Payer'); |
74
|
|
|
|
75
|
|
|
$quote = $this->getMockBuilder(Quote::class) |
76
|
|
|
->disableOriginalConstructor() |
77
|
|
|
->setMethods(['getQuoteCurrencyCode', 'getBillingAddress']) |
78
|
|
|
->getMock(); |
79
|
|
|
$quote->method('getQuoteCurrencyCode')->willReturn('EUR'); |
80
|
|
|
$quote->method('getBillingAddress')->willReturn($address); |
81
|
|
|
|
82
|
|
|
$payment = $this->getMockBuilder(Paypal::class)->disableOriginalConstructor()->getMock(); |
83
|
|
|
$payment->method('getOperationMode')->willReturn('test'); |
84
|
|
|
$payment->method('getClearingtype')->willReturn('fnc'); |
85
|
|
|
$payment->method('getSubType')->willReturn('PYD'); |
86
|
|
|
|
87
|
|
|
$this->shopHelper->method('getConfigParam')->willReturn('12345'); |
88
|
|
|
|
89
|
|
|
$response = ['status' => 'APPROVED']; |
90
|
|
|
$this->apiHelper->method('sendApiRequest')->willReturn($response); |
91
|
|
|
|
92
|
|
|
$result = $this->classToTest->sendRequest($payment, $quote, 100); |
93
|
|
|
$this->assertEquals($response, $result); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.