-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathExpireWebhookHandlerTest.php
More file actions
178 lines (145 loc) · 6.61 KB
/
ExpireWebhookHandlerTest.php
File metadata and controls
178 lines (145 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Test\Unit\Helper\Webhook;
use Adyen\Payment\Helper\ChargedCurrency;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Helper\Order as OrderHelper;
use Adyen\Payment\Helper\Webhook\ExpireWebhookHandler;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\AdyenAmountCurrency;
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order;
use PHPUnit\Framework\MockObject\MockObject;
class ExpireWebhookHandlerTest extends AbstractAdyenTestCase
{
protected ?ExpireWebhookHandler $webhookHandler;
protected Config|MockObject $configMock;
protected OrderHelper|MockObject $orderHelperMock;
protected Data|MockObject $adyenHelperMock;
protected AdyenLogger|MockObject $adyenLoggerMock;
protected ChargedCurrency|MockObject $chargedCurrencyMock;
protected Order|MockObject $orderMock;
protected Notification|MockObject $notificationMock;
protected function setUp(): void
{
// Generic mock items
$this->orderMock = $this->createMock(Order::class);
$this->orderMock->method('getStoreId')->willReturn(1);
$this->notificationMock = $this->createMock(Notification::class);
$this->notificationMock->method('getEventCode')->willReturn(Notification::EXPIRE);
// Constructor arguments
$this->configMock = $this->createMock(Config::class);
$this->orderHelperMock = $this->createMock(OrderHelper::class);
$this->adyenHelperMock = $this->createPartialMock(Data::class, []);
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);
$this->chargedCurrencyMock = $this->createMock(ChargedCurrency::class);
$this->webhookHandler = new ExpireWebhookHandler(
$this->configMock,
$this->orderHelperMock,
$this->adyenHelperMock,
$this->adyenLoggerMock,
$this->chargedCurrencyMock
);
}
protected function tearDown(): void
{
$this->webhookHandler = null;
}
public function testExpireWebhookIgnored()
{
$this->configMock->expects($this->once())
->method('isExpireWebhookIgnored')
->willReturn(true);
$this->adyenLoggerMock->expects($this->once())->method('addAdyenNotification');
$this->orderMock->expects($this->once())->method('addCommentToStatusHistory');
$this->orderHelperMock->expects($this->never())->method('holdCancelOrder');
$result = $this->webhookHandler->handleWebhook(
$this->orderMock,
$this->notificationMock,
'pending'
);
$this->assertInstanceOf(OrderInterface::class, $result);
}
public function testHandleWebhookWithPartialExpiration()
{
$this->configMock->expects($this->once())
->method('isExpireWebhookIgnored')
->willReturn(false);
$this->adyenLoggerMock->expects($this->once())->method('addAdyenNotification');
$this->orderHelperMock->expects($this->never())->method('holdCancelOrder');
$this->notificationMock->method('getAmountValue')->willReturn(2000);
$orderAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class);
$orderAmountCurrencyMock->method('getAmount')->willReturn(45.00);
$orderAmountCurrencyMock->method('getCurrencyCode')->willReturn('EUR');
$this->chargedCurrencyMock->expects($this->once())
->method('getOrderAmountCurrency')
->willReturn($orderAmountCurrencyMock);
$this->orderMock->expects($this->once())->method('addCommentToStatusHistory');
$result = $this->webhookHandler->handleWebhook(
$this->orderMock,
$this->notificationMock,
'pending'
);
$this->assertInstanceOf(OrderInterface::class, $result);
}
public function testHandleWebhookWithShipments()
{
$this->configMock->expects($this->once())
->method('isExpireWebhookIgnored')
->willReturn(false);
$this->adyenLoggerMock->expects($this->once())->method('addAdyenNotification');
$this->orderHelperMock->expects($this->never())->method('holdCancelOrder');
$this->notificationMock->method('getAmountValue')->willReturn(4500);
$orderAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class);
$orderAmountCurrencyMock->method('getAmount')->willReturn(45.00);
$orderAmountCurrencyMock->method('getCurrencyCode')->willReturn('EUR');
$this->chargedCurrencyMock->expects($this->once())
->method('getOrderAmountCurrency')
->willReturn($orderAmountCurrencyMock);
$this->orderMock->expects($this->once())->method('hasShipments')->willReturn(true);
$this->orderMock->expects($this->once())->method('addCommentToStatusHistory');
$result = $this->webhookHandler->handleWebhook(
$this->orderMock,
$this->notificationMock,
'pending'
);
$this->assertInstanceOf(OrderInterface::class, $result);
}
public function testHandleWebhookSuccessfully()
{
$this->configMock->expects($this->once())
->method('isExpireWebhookIgnored')
->willReturn(false);
$this->adyenLoggerMock->expects($this->once())->method('addAdyenNotification');
$this->notificationMock->method('getAmountValue')->willReturn(4500);
$orderAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class);
$orderAmountCurrencyMock->method('getAmount')->willReturn(45.00);
$orderAmountCurrencyMock->method('getCurrencyCode')->willReturn('EUR');
$this->chargedCurrencyMock->expects($this->once())
->method('getOrderAmountCurrency')
->willReturn($orderAmountCurrencyMock);
$this->orderMock->expects($this->once())->method('hasShipments')->willReturn(false);
$this->orderMock->expects($this->once())->method('addCommentToStatusHistory');
$this->orderHelperMock->expects($this->once())
->method('holdCancelOrder')
->with($this->orderMock, false)
->willReturn($this->orderMock);
$result = $this->webhookHandler->handleWebhook(
$this->orderMock,
$this->notificationMock,
'pending'
);
$this->assertInstanceOf(OrderInterface::class, $result);
}
}