Skip to content

Commit 939e1de

Browse files
committed
Clean expired quotes - Fix out of memory on huge quotes list
1 parent 7e9fd80 commit 939e1de

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

dev/tests/integration/testsuite/Magento/Sales/Cron/CleanExpiredQuotesTest.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ class CleanExpiredQuotesTest extends \PHPUnit\Framework\TestCase
2525
*/
2626
private $cleanExpiredQuotes;
2727

28-
/**
29-
* @var QuoteRepository
30-
*/
31-
private $quoteRepository;
32-
33-
/**
34-
* @var SearchCriteriaBuilder
35-
*/
36-
private $searchCriteriaBuilder;
37-
3828
/**
3929
* @var QuoteCollectionFactory
4030
*/
@@ -47,8 +37,6 @@ protected function setUp()
4737
{
4838
$objectManager = Bootstrap::getObjectManager();
4939
$this->cleanExpiredQuotes = $objectManager->get(CleanExpiredQuotes::class);
50-
$this->quoteRepository = $objectManager->get(QuoteRepository::class);
51-
$this->searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
5240
$this->quoteCollectionFactory = $objectManager->get(QuoteCollectionFactory::class);
5341
}
5442

@@ -60,18 +48,14 @@ protected function setUp()
6048
*/
6149
public function testExecute()
6250
{
63-
$searchCriteria = $this->searchCriteriaBuilder->create();
6451
//Initial count - should be equal to stores number.
65-
$this->assertEquals(2, $this->quoteRepository->getList($searchCriteria)->getTotalCount());
52+
$this->assertQuotesCount(2);
6653

6754
//Deleting expired quotes
6855
$this->cleanExpiredQuotes->execute();
69-
$totalCount = $this->quoteRepository->getList($searchCriteria)->getTotalCount();
56+
7057
//Only 1 will be deleted for the store that has all of them expired by config (default_store)
71-
$this->assertEquals(
72-
1,
73-
$totalCount
74-
);
58+
$this->assertQuotesCount(1);
7559
}
7660

7761
/**
@@ -83,14 +67,24 @@ public function testExecute()
8367
public function testExecuteWithBigAmountOfQuotes()
8468
{
8569
//Initial count - should be equal to 1000
86-
//Use collection getSize in order to get quick result
87-
$this->assertEquals(1000, $this->quoteCollectionFactory->create()->getSize());
70+
$this->assertQuotesCount(1000);
8871

8972
//Deleting expired quotes
9073
$this->cleanExpiredQuotes->execute();
91-
$totalCount = $this->quoteCollectionFactory->create()->getSize();
9274

9375
//There should be no quotes anymore
94-
$this->assertEquals(0, $totalCount);
76+
$this->assertQuotesCount(0);
77+
}
78+
79+
/**
80+
* Optimized assert quotes count
81+
* Uses collection getSize in order to get quick result
82+
*
83+
* @param int $expected
84+
*/
85+
private function assertQuotesCount(int $expected): void
86+
{
87+
$totalCount = $this->quoteCollectionFactory->create()->getSize();
88+
$this->assertEquals($expected, $totalCount);
9589
}
9690
}

0 commit comments

Comments
 (0)