|
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\Observer\Transactionstatus; |
|
28
|
|
|
|
|
29
|
|
|
use Payone\Core\Observer\Transactionstatus\Appointed as ClassToTest; |
|
30
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
|
31
|
|
|
use Magento\Framework\Event\Observer; |
|
32
|
|
|
use Magento\Sales\Model\Order; |
|
33
|
|
|
use Magento\Sales\Model\Order\Email\Sender\OrderSender; |
|
34
|
|
|
use Payone\Core\Model\Methods\Creditcard; |
|
35
|
|
|
use Magento\Sales\Model\Order\Payment; |
|
36
|
|
|
use Payone\Core\Model\PayoneConfig; |
|
37
|
|
|
use Magento\Sales\Model\Service\InvoiceService; |
|
38
|
|
|
use Magento\Sales\Model\Order\Invoice; |
|
39
|
|
|
use Payone\Core\Helper\Base; |
|
40
|
|
|
use Payone\Core\Test\Unit\BaseTestCase; |
|
41
|
|
|
use Payone\Core\Test\Unit\PayoneObjectManager; |
|
42
|
|
|
|
|
43
|
|
|
class AppointedTest extends BaseTestCase |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* @var ClassToTest |
|
47
|
|
|
*/ |
|
48
|
|
|
private $classToTest; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var ObjectManager|PayoneObjectManager |
|
52
|
|
|
*/ |
|
53
|
|
|
private $objectManager; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var OrderSender|\PHPUnit_Framework_MockObject_MockObject |
|
57
|
|
|
*/ |
|
58
|
|
|
private $orderSender; |
|
59
|
|
|
|
|
60
|
|
|
protected function setUp() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->objectManager = $this->getObjectManager(); |
|
63
|
|
|
|
|
64
|
|
|
$this->orderSender = $this->getMockBuilder(OrderSender::class)->disableOriginalConstructor()->getMock(); |
|
65
|
|
|
|
|
66
|
|
|
$invoice = $this->getMockBuilder(Invoice::class)->disableOriginalConstructor()->getMock(); |
|
67
|
|
|
|
|
68
|
|
|
$invoiceService = $this->getMockBuilder(InvoiceService::class)->disableOriginalConstructor()->getMock(); |
|
69
|
|
|
$invoiceService->method('prepareInvoice')->willReturn($invoice); |
|
70
|
|
|
|
|
71
|
|
|
$baseHelper = $this->getMockBuilder(Base::class)->disableOriginalConstructor()->getMock(); |
|
72
|
|
|
$baseHelper->method('getConfigParam')->willReturn('1'); |
|
73
|
|
|
|
|
74
|
|
|
$this->classToTest = $this->objectManager->getObject(ClassToTest::class, [ |
|
75
|
|
|
'orderSender' => $this->orderSender, |
|
76
|
|
|
'invoiceService' => $invoiceService, |
|
77
|
|
|
'baseHelper' => $baseHelper |
|
78
|
|
|
]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testExecute() |
|
82
|
|
|
{ |
|
83
|
|
|
$method = $this->getMockBuilder(Creditcard::class)->disableOriginalConstructor()->getMock(); |
|
84
|
|
|
$method->method('getCode')->willReturn(PayoneConfig::METHOD_CREDITCARD); |
|
85
|
|
|
|
|
86
|
|
|
$payment = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock(); |
|
87
|
|
|
$payment->method('getLastTransId')->willReturn('123'); |
|
88
|
|
|
$payment->method('getMethodInstance')->willReturn($method); |
|
89
|
|
|
|
|
90
|
|
|
$order = $this->getMockBuilder(Order::class) |
|
91
|
|
|
->disableOriginalConstructor() |
|
92
|
|
|
->setMethods(['getPayment', 'getEmailSent', 'getPayoneAuthmode', 'save']) |
|
93
|
|
|
->getMock(); |
|
94
|
|
|
$order->method('getPayment')->willReturn($payment); |
|
95
|
|
|
$order->method('getPayoneAuthmode')->willReturn('authorization'); |
|
96
|
|
|
|
|
97
|
|
|
$observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); |
|
98
|
|
|
$observer->method('getOrder')->willReturn($order); |
|
99
|
|
|
|
|
100
|
|
|
$result = $this->classToTest->execute($observer); |
|
|
|
|
|
|
101
|
|
|
$this->assertNull($result); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testExecuteException() |
|
105
|
|
|
{ |
|
106
|
|
|
$exception = new \Exception(); |
|
107
|
|
|
$this->orderSender->method('send')->willThrowException($exception); |
|
108
|
|
|
|
|
109
|
|
|
$method = $this->getMockBuilder(Creditcard::class)->disableOriginalConstructor()->getMock(); |
|
110
|
|
|
$method->method('getCode')->willReturn(PayoneConfig::METHOD_ADVANCE_PAYMENT); |
|
111
|
|
|
|
|
112
|
|
|
$payment = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock(); |
|
113
|
|
|
$payment->method('getLastTransId')->willReturn('123'); |
|
114
|
|
|
$payment->method('getMethodInstance')->willReturn($method); |
|
115
|
|
|
|
|
116
|
|
|
$order = $this->getMockBuilder(Order::class) |
|
117
|
|
|
->disableOriginalConstructor() |
|
118
|
|
|
->setMethods(['getPayment', 'getEmailSent', 'getPayoneAuthmode', 'save']) |
|
119
|
|
|
->getMock(); |
|
120
|
|
|
$order->method('getPayment')->willReturn($payment); |
|
121
|
|
|
$order->method('getPayoneAuthmode')->willReturn('authorization'); |
|
122
|
|
|
|
|
123
|
|
|
$observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); |
|
124
|
|
|
$observer->method('getOrder')->willReturn($order); |
|
125
|
|
|
|
|
126
|
|
|
$result = $this->classToTest->execute($observer); |
|
|
|
|
|
|
127
|
|
|
$this->assertNull($result); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
View Code Duplication |
public function testExecuteNoOrder() |
|
|
|
|
|
|
131
|
|
|
{ |
|
132
|
|
|
$observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); |
|
133
|
|
|
$observer->method('getOrder')->willReturn(null); |
|
134
|
|
|
|
|
135
|
|
|
$result = $this->classToTest->execute($observer); |
|
|
|
|
|
|
136
|
|
|
$this->assertNull($result); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.