Skip to content

Commit

Permalink
[EPC-9177] Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Demiralp committed Feb 3, 2025
1 parent 8edd0c7 commit 4fc60c5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 35 deletions.
14 changes: 0 additions & 14 deletions Test/Unit/Cron/CleanupNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,31 @@
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\DB\Adapter\DeadlockException;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;

class CleanupNotificationsTest extends AbstractAdyenTestCase
{
protected ?CleanupNotifications $cleanupNotifications;
protected AdyenLogger|MockObject $adyenLoggerMock;
protected Config|MockObject $configHelperMock;
protected StoreManagerInterface|MockObject $storeManagerMock;
protected AdyenNotificationRepositoryInterface|MockObject $adyenNotificationRepositoryMock;
protected NotificationsProviderInterface|MockObject $notificationsProvider;
protected array $providers;

const STORE_ID = PHP_INT_MAX;

protected function setUp(): void
{
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);
$this->configHelperMock = $this->createMock(Config::class);
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
$this->adyenNotificationRepositoryMock =
$this->createMock(AdyenNotificationRepositoryInterface::class);
$this->notificationsProvider = $this->createMock(NotificationsProviderInterface::class);

$this->providers[] = $this->notificationsProvider;

$storeMock = $this->createMock(StoreInterface::class);
$storeMock->method('getId')->willReturn(self::STORE_ID);
$this->storeManagerMock->method('getStore')->willReturn($storeMock);

$this->cleanupNotifications = new CleanupNotifications(
$this->providers,
$this->adyenLoggerMock,
$this->configHelperMock,
$this->storeManagerMock,
$this->adyenNotificationRepositoryMock
);
}
Expand All @@ -68,7 +57,6 @@ public function testExecuteConfigEnabled()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->with(self::STORE_ID)
->willReturn(true);

$notificationMock = $this->createMock(Notification::class);
Expand All @@ -90,7 +78,6 @@ public function testExecuteConfigDisabled()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->with(self::STORE_ID)
->willReturn(false);

$this->notificationsProvider->expects($this->never())->method('provide');
Expand All @@ -104,7 +91,6 @@ public function testExecuteException()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->with(self::STORE_ID)
->willReturn(true);

$notificationMock = $this->createMock(Notification::class);
Expand Down
13 changes: 0 additions & 13 deletions Test/Unit/Cron/Providers/ProcessedOldNotificationsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;

class ProcessedOldNotificationsProviderTest extends AbstractAdyenTestCase
Expand All @@ -31,29 +29,20 @@ class ProcessedOldNotificationsProviderTest extends AbstractAdyenTestCase
protected AdyenNotificationRepositoryInterface|MockObject $adyenNotificationRepositoryMock;
protected SearchCriteriaBuilder|MockObject $searchCriteriaBuilderMock;
protected Config|MockObject $configHelperMock;
protected StoreManagerInterface|MockObject $storeManagerMock;
protected AdyenLogger|MockObject $adyenLoggerMock;

const STORE_ID = PHP_INT_MAX;

protected function setUp(): void
{
$this->adyenNotificationRepositoryMock =
$this->createMock(AdyenNotificationRepositoryInterface::class);
$this->searchCriteriaBuilderMock = $this->createMock(SearchCriteriaBuilder::class);
$this->configHelperMock = $this->createMock(Config::class);
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);

$storeMock = $this->createMock(StoreInterface::class);
$storeMock->method('getId')->willReturn(self::STORE_ID);
$this->storeManagerMock->method('getStore')->willReturn($storeMock);

$this->notificationsProvider = new ProcessedOldNotificationsProvider(
$this->adyenNotificationRepositoryMock,
$this->searchCriteriaBuilderMock,
$this->configHelperMock,
$this->storeManagerMock,
$this->adyenLoggerMock
);
}
Expand All @@ -69,7 +58,6 @@ public function testProvideSuccess()

$this->configHelperMock->expects($this->once())
->method('getRequiredDaysForOldWebhooks')
->with(self::STORE_ID)
->willReturn($expiryDays);

$dateMock = date('Y-m-d H:i:s', time() - $expiryDays * 24 * 60 * 60);
Expand Down Expand Up @@ -112,7 +100,6 @@ public function testProvideFailure()

$this->configHelperMock->expects($this->once())
->method('getRequiredDaysForOldWebhooks')
->with(self::STORE_ID)
->willReturn($expiryDays);

$dateMock = date('Y-m-d H:i:s', time() - $expiryDays * 24 * 60 * 60);
Expand Down
12 changes: 4 additions & 8 deletions Test/Unit/Helper/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ public function testGetIsCvcRequiredForRecurringCardPayments()

public function testGetIsWebhookCleanupEnabled()
{
$storeId = PHP_INT_MAX;

$path = sprintf(
"%s/%s/%s",
Config::XML_PAYMENT_PREFIX,
Expand All @@ -183,17 +181,15 @@ public function testGetIsWebhookCleanupEnabled()

$this->scopeConfigMock->expects($this->once())
->method('isSetFlag')
->with($this->equalTo($path), $this->equalTo(ScopeInterface::SCOPE_STORE), $this->equalTo($storeId))
->with($this->equalTo($path), $this->equalTo(ScopeInterface::SCOPE_STORE), $this->equalTo(null))
->willReturn(true);

$result = $this->configHelper->getIsWebhookCleanupEnabled($storeId);
$result = $this->configHelper->getIsWebhookCleanupEnabled();
$this->assertTrue($result);
}

public function testGetRequiredDaysForOldWebhooks()
{
$storeId = PHP_INT_MAX;

$path = sprintf(
"%s/%s/%s",
Config::XML_PAYMENT_PREFIX,
Expand All @@ -203,10 +199,10 @@ public function testGetRequiredDaysForOldWebhooks()

$this->scopeConfigMock->expects($this->once())
->method('getValue')
->with($this->equalTo($path), $this->equalTo(ScopeInterface::SCOPE_STORE), $this->equalTo($storeId))
->with($this->equalTo($path), $this->equalTo(ScopeInterface::SCOPE_STORE), $this->equalTo(null))
->willReturn("90");

$result = $this->configHelper->getRequiredDaysForOldWebhooks($storeId);
$result = $this->configHelper->getRequiredDaysForOldWebhooks();
$this->assertIsInt($result);
$this->assertEquals(90, $result);
}
Expand Down

0 comments on commit 4fc60c5

Please sign in to comment.