Skip to content

Commit 0afb89e

Browse files
committed
ACP2E-3493: fix static and unit test errors, small refactoring
1 parent cb1c806 commit 0afb89e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/code/Magento/Persistent/Model/CleanExpiredPersistentQuotes.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function execute(int $websiteId): void
6161
private function processStoreQuotes(StoreInterface $store): void
6262
{
6363
$batchSize = 500;
64-
$lastProcessedId = 0;
64+
$lastProcessedId = $count = 0;
6565

6666
while (true) {
6767
$quotesToProcess = $this->expiredPersistentQuotesCollection
@@ -72,6 +72,7 @@ private function processStoreQuotes(StoreInterface $store): void
7272
}
7373

7474
foreach ($quotesToProcess as $quote) {
75+
$count++;
7576
try {
7677
$this->quoteRepository->delete($quote);
7778
$lastProcessedId = (int)$quote->getId();
@@ -82,12 +83,14 @@ private function processStoreQuotes(StoreInterface $store): void
8283
(string)$e
8384
));
8485
}
86+
if ($count % $batchSize === 0) {
87+
$this->snapshot->clear($quote);
88+
}
8589
$quote->clearInstance();
8690
unset($quote);
8791
}
8892

8993
$quotesToProcess->clear();
90-
$this->snapshot->clear();
9194
unset($quotesToProcess);
9295
}
9396
}

app/code/Magento/Persistent/Test/Unit/Model/CleanExpiredPersistentQuotesTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
use Magento\Store\Model\StoreManagerInterface;
1717
use Magento\Quote\Model\ResourceModel\Quote\Collection;
1818
use PHPUnit\Framework\MockObject\Exception;
19+
use PHPUnit\Framework\MockObject\MockObject;
1920
use PHPUnit\Framework\TestCase;
2021
use Psr\Log\LoggerInterface;
2122
use Magento\Store\Api\Data\StoreInterface;
2223
use Magento\Store\Model\Website;
2324

25+
/**
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
*/
2428
class CleanExpiredPersistentQuotesTest extends TestCase
2529
{
2630
/**
@@ -38,6 +42,11 @@ class CleanExpiredPersistentQuotesTest extends TestCase
3842
*/
3943
private QuoteRepository $quoteRepositoryMock;
4044

45+
/**
46+
* @var MockObject|Snapshot
47+
*/
48+
private MockObject|Snapshot $snapshotMock;
49+
4150
/**
4251
* @var LoggerInterface
4352
*/

0 commit comments

Comments
 (0)