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; |
28
|
|
|
|
29
|
|
|
use Magento\Quote\Model\Quote\Address; |
30
|
|
|
use Payone\Core\Helper\Database; |
31
|
|
|
use Payone\Core\Model\Api\Request\Consumerscore as ClassToTest; |
32
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
33
|
|
|
use Payone\Core\Helper\Api; |
34
|
|
|
use Payone\Core\Helper\Shop; |
35
|
|
|
use Payone\Core\Model\ResourceModel\CheckedAddresses; |
36
|
|
|
|
37
|
|
|
class ConsumerscoreTest extends \PHPUnit_Framework_TestCase |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* @var ClassToTest |
41
|
|
|
*/ |
42
|
|
|
private $classToTest; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var Api|\PHPUnit_Framework_MockObject_MockObject |
46
|
|
|
*/ |
47
|
|
|
private $apiHelper; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Shop|\PHPUnit_Framework_MockObject_MockObject |
51
|
|
|
*/ |
52
|
|
|
private $shopHelper; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var CheckedAddresses|\PHPUnit_Framework_MockObject_MockObject |
56
|
|
|
*/ |
57
|
|
|
private $addressesChecked; |
58
|
|
|
|
59
|
|
|
protected function setUp() |
60
|
|
|
{ |
61
|
|
|
$objectManager = new ObjectManager($this); |
62
|
|
|
|
63
|
|
|
$databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock(); |
64
|
|
|
$databaseHelper->method('getSequenceNumber')->willReturn('0'); |
65
|
|
|
|
66
|
|
|
$this->apiHelper = $this->getMockBuilder(Api::class)->disableOriginalConstructor()->getMock(); |
67
|
|
|
$this->shopHelper = $this->getMockBuilder(Shop::class)->disableOriginalConstructor()->getMock(); |
68
|
|
|
$this->addressesChecked = $this->getMockBuilder(CheckedAddresses::class)->disableOriginalConstructor()->getMock(); |
69
|
|
|
|
70
|
|
|
$this->classToTest = $objectManager->getObject(ClassToTest::class, [ |
71
|
|
|
'databaseHelper' => $databaseHelper, |
72
|
|
|
'apiHelper' => $this->apiHelper, |
73
|
|
|
'shopHelper' => $this->shopHelper, |
74
|
|
|
'addressesChecked' => $this->addressesChecked |
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testSendRequest() |
79
|
|
|
{ |
80
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
81
|
|
|
$address->method('getCountryId')->willReturn('DE'); |
82
|
|
|
|
83
|
|
|
$address->method('getFirstname')->willReturn('Paul'); |
84
|
|
|
$address->method('getLastname')->willReturn('Paytest'); |
85
|
|
|
$address->method('getCompany')->willReturn('Testcompany Ltd.'); |
86
|
|
|
$address->method('getStreet')->willReturn(['Teststr. 5', '1st floor']); |
87
|
|
|
$address->method('getPostcode')->willReturn('12345'); |
88
|
|
|
$address->method('getCity')->willReturn('Berlin'); |
89
|
|
|
$address->method('getRegionCode')->willReturn('Berlin'); |
90
|
|
|
|
91
|
|
|
$this->addressesChecked->method('wasAddressCheckedBefore')->willReturn(false); |
92
|
|
|
|
93
|
|
|
$response = ['status' => 'VALID']; |
94
|
|
|
$this->apiHelper->method('sendApiRequest')->willReturn($response); |
95
|
|
|
|
96
|
|
|
$this->shopHelper->expects($this->any()) |
|
|
|
|
97
|
|
|
->method('getConfigParam') |
98
|
|
|
->willReturnMap([ |
99
|
|
|
['enabled', 'creditrating', 'payone_protect', null, true], |
100
|
|
|
['mode', 'creditrating', 'payone_protect', null, 'test'], |
101
|
|
|
['aid', 'global', 'payone_general', null, '12345'], |
102
|
|
|
['addresscheck', 'creditrating', 'payone_protect', null, 'test'], |
103
|
|
|
['type', 'creditrating', 'payone_protect', null, 'test'], |
104
|
|
|
]); |
105
|
|
|
|
106
|
|
|
$result = $this->classToTest->sendRequest($address); |
107
|
|
|
$this->assertArrayHasKey('status', $result); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testSendRequestTrue() |
111
|
|
|
{ |
112
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
113
|
|
|
$address->method('getCountryId')->willReturn('DE'); |
114
|
|
|
|
115
|
|
|
$address->method('getFirstname')->willReturn('Paul'); |
116
|
|
|
$address->method('getLastname')->willReturn('Paytest'); |
117
|
|
|
$address->method('getCompany')->willReturn('Testcompany Ltd.'); |
118
|
|
|
$address->method('getStreet')->willReturn(['Teststr. 5', '1st floor']); |
119
|
|
|
$address->method('getPostcode')->willReturn('12345'); |
120
|
|
|
$address->method('getCity')->willReturn('Berlin'); |
121
|
|
|
$address->method('getRegionCode')->willReturn('Berlin'); |
122
|
|
|
|
123
|
|
|
$this->addressesChecked->method('wasAddressCheckedBefore')->willReturn(true); |
124
|
|
|
|
125
|
|
|
$this->shopHelper->expects($this->any()) |
|
|
|
|
126
|
|
|
->method('getConfigParam') |
127
|
|
|
->willReturnMap([ |
128
|
|
|
['enabled', 'creditrating', 'payone_protect', null, true], |
129
|
|
|
['mode', 'creditrating', 'payone_protect', null, 'test'], |
130
|
|
|
['aid', 'global', 'payone_general', null, '12345'], |
131
|
|
|
['addresscheck', 'creditrating', 'payone_protect', null, 'test'], |
132
|
|
|
['type', 'creditrating', 'payone_protect', null, 'test'], |
133
|
|
|
]); |
134
|
|
|
|
135
|
|
|
$result = $this->classToTest->sendRequest($address); |
136
|
|
|
$this->assertTrue($result); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
View Code Duplication |
public function testSendRequestNotNeeded() |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
142
|
|
|
|
143
|
|
|
$this->shopHelper->method('getConfigParam')->willReturn(false); |
144
|
|
|
|
145
|
|
|
$result = $this->classToTest->sendRequest($address); |
146
|
|
|
$this->assertTrue($result); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: