-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathCleanupNotificationsTest.php
110 lines (88 loc) · 3.76 KB
/
CleanupNotificationsTest.php
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
<?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\Cron;
use Adyen\Payment\Api\Repository\AdyenNotificationRepositoryInterface;
use Adyen\Payment\Cron\CleanupNotifications;
use Adyen\Payment\Cron\Providers\NotificationsProviderInterface;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\DB\Adapter\DeadlockException;
use PHPUnit\Framework\MockObject\MockObject;
class CleanupNotificationsTest extends AbstractAdyenTestCase
{
protected ?CleanupNotifications $cleanupNotifications;
protected AdyenLogger|MockObject $adyenLoggerMock;
protected Config|MockObject $configHelperMock;
protected AdyenNotificationRepositoryInterface|MockObject $adyenNotificationRepositoryMock;
protected NotificationsProviderInterface|MockObject $notificationsProvider;
protected array $providers;
protected function setUp(): void
{
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);
$this->configHelperMock = $this->createMock(Config::class);
$this->adyenNotificationRepositoryMock =
$this->createMock(AdyenNotificationRepositoryInterface::class);
$this->notificationsProvider = $this->createMock(NotificationsProviderInterface::class);
$this->providers[] = $this->notificationsProvider;
$this->cleanupNotifications = new CleanupNotifications(
$this->providers,
$this->adyenLoggerMock,
$this->configHelperMock,
$this->adyenNotificationRepositoryMock
);
}
protected function tearDown(): void
{
$this->cleanupNotifications = null;
}
public function testExecuteConfigEnabled()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->willReturn(true);
$notificationMock = $this->createMock(Notification::class);
$providerResult[] = $notificationMock;
$this->notificationsProvider->method('provide')->willReturn($providerResult);
$this->adyenNotificationRepositoryMock->expects($this->once())
->method('delete')
->with($notificationMock)
->willReturn(true);
$this->adyenLoggerMock->expects($this->once())->method('addAdyenDebug');
$this->cleanupNotifications->execute();
}
public function testExecuteConfigDisabled()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->willReturn(false);
$this->notificationsProvider->expects($this->never())->method('provide');
$this->adyenNotificationRepositoryMock->expects($this->never())->method('delete');
$this->adyenLoggerMock->expects($this->once())->method('addAdyenDebug');
$this->cleanupNotifications->execute();
}
public function testExecuteException()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->willReturn(true);
$notificationMock = $this->createMock(Notification::class);
$providerResult[] = $notificationMock;
$this->notificationsProvider->method('provide')->willReturn($providerResult);
$this->adyenNotificationRepositoryMock->expects($this->once())
->method('delete')
->with($notificationMock)
->willThrowException(new DeadlockException());
$this->adyenLoggerMock->expects($this->once())->method('error');
$this->cleanupNotifications->execute();
}
}