Skip to content

Commit 3945138

Browse files
Fixing unit test errors
1 parent f5ae04b commit 3945138

File tree

3 files changed

+13
-38
lines changed

3 files changed

+13
-38
lines changed

app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProductsPriceProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function execute(
5959
: $this->getDateInterval(Store::DEFAULT_STORE_ID);
6060

6161
while ($ruleData = $productsStmt->fetch()) {
62-
$ruleProductId = $ruleData['product_id'];
62+
$ruleProductId = (int)$ruleData['product_id'];
6363
$productKey = $ruleProductId .
6464
'_' .
6565
$ruleData['website_id'] .
@@ -99,7 +99,7 @@ public function execute(
9999
* @param array $ruleData
100100
* @param DateTime $date
101101
* @param string $productKey
102-
* @param string $ruleProductId
102+
* @param int $ruleProductId
103103
* @param array $dayPrices
104104
* @param array $stopFlags
105105
* @return void
@@ -108,7 +108,7 @@ private function processDate(
108108
array $ruleData,
109109
DateTime $date,
110110
string $productKey,
111-
string $ruleProductId,
111+
int $ruleProductId,
112112
array &$dayPrices,
113113
array &$stopFlags
114114
): void {

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/ReindexRuleProductPriceTest.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
use Magento\CatalogRule\Model\Indexer\ProductPriceCalculator;
1111
use Magento\CatalogRule\Model\Indexer\ReindexRuleProductPrice;
12+
use Magento\CatalogRule\Model\Indexer\ReindexRuleProductsPriceProcessor;
1213
use Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor;
1314
use Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder;
1415
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
15-
use Magento\Store\Api\Data\GroupInterface;
1616
use Magento\Store\Api\Data\WebsiteInterface;
1717
use Magento\Store\Model\StoreManagerInterface;
1818
use PHPUnit\Framework\MockObject\MockObject;
@@ -50,6 +50,11 @@ class ReindexRuleProductPriceTest extends TestCase
5050
*/
5151
private $pricesPersistorMock;
5252

53+
/**
54+
* @var ReindexRuleProductsPriceProcessor|MockObject
55+
*/
56+
private $reindexRuleProductsPriceProcessorMock;
57+
5358
/**
5459
* @inheritDoc
5560
*/
@@ -60,14 +65,16 @@ protected function setUp(): void
6065
$this->productPriceCalculatorMock = $this->createMock(ProductPriceCalculator::class);
6166
$this->localeDate = $this->getMockForAbstractClass(TimezoneInterface::class);
6267
$this->pricesPersistorMock = $this->createMock(RuleProductPricesPersistor::class);
68+
$this->reindexRuleProductsPriceProcessorMock = $this->createMock(ReindexRuleProductsPriceProcessor::class);
6369

6470
$this->model = new ReindexRuleProductPrice(
6571
$this->storeManagerMock,
6672
$this->ruleProductsSelectBuilderMock,
6773
$this->productPriceCalculatorMock,
6874
$this->localeDate,
6975
$this->pricesPersistorMock,
70-
true
76+
true,
77+
$this->reindexRuleProductsPriceProcessorMock
7178
);
7279
}
7380

@@ -77,30 +84,15 @@ protected function setUp(): void
7784
public function testExecute(): void
7885
{
7986
$websiteId = 234;
80-
$defaultGroupId = 11;
81-
$defaultStoreId = 22;
8287
$productId = 55;
8388

8489
$websiteMock = $this->getMockForAbstractClass(WebsiteInterface::class);
8590
$websiteMock->expects($this->once())
8691
->method('getId')
8792
->willReturn($websiteId);
88-
$websiteMock->expects($this->once())
89-
->method('getDefaultGroupId')
90-
->willReturn($defaultGroupId);
9193
$this->storeManagerMock->expects($this->once())
9294
->method('getWebsites')
9395
->willReturn([$websiteMock]);
94-
$groupMock = $this->getMockForAbstractClass(GroupInterface::class);
95-
$groupMock->method('getId')
96-
->willReturn($defaultStoreId);
97-
$groupMock->expects($this->once())
98-
->method('getDefaultStoreId')
99-
->willReturn($defaultStoreId);
100-
$this->storeManagerMock->expects($this->once())
101-
->method('getGroup')
102-
->with($defaultGroupId)
103-
->willReturn($groupMock);
10496

10597
$statementMock = $this->createMock(\Zend_Db_Statement_Interface::class);
10698
$this->ruleProductsSelectBuilderMock->expects($this->once())
@@ -117,18 +109,11 @@ public function testExecute(): void
117109
'action_stop' => true
118110
];
119111

120-
$this->localeDate->expects($this->once())
121-
->method('scopeDate')
122-
->with($defaultStoreId, null, true)
123-
->willReturn(new \DateTime());
124-
125112
$statementMock
126113
->method('fetch')
127114
->willReturnOnConsecutiveCalls($ruleData, false);
128115

129-
$this->productPriceCalculatorMock->expects($this->atLeastOnce())
130-
->method('calculate');
131-
$this->pricesPersistorMock->expects($this->once())
116+
$this->reindexRuleProductsPriceProcessorMock->expects($this->once())
132117
->method('execute');
133118

134119
$this->assertTrue($this->model->execute(1, $productId, true));

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/ReindexRuleProductsPriceProcessorTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\CatalogRule\Model\Indexer\ProductPriceCalculator;
1010
use Magento\CatalogRule\Model\Indexer\ReindexRuleProductsPriceProcessor;
1111
use Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor;
12-
use Magento\Framework\Exception\LocalizedException;
1312
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1413
use Magento\Store\Api\Data\GroupInterface;
1514
use Magento\Store\Api\Data\WebsiteInterface;
@@ -67,23 +66,14 @@ protected function setUp(): void
6766
*/
6867
public function testExecute(): void
6968
{
70-
$websiteId = 234;
7169
$defaultGroupId = 11;
7270
$defaultStoreId = 22;
7371

7472
$websiteMock = $this->getMockForAbstractClass(WebsiteInterface::class);
75-
$websiteMock->expects($this->once())
76-
->method('getId')
77-
->willReturn($websiteId);
7873
$websiteMock->expects($this->once())
7974
->method('getDefaultGroupId')
8075
->willReturn($defaultGroupId);
81-
$this->storeManagerMock->expects($this->once())
82-
->method('getWebsites')
83-
->willReturn([$websiteMock]);
8476
$groupMock = $this->getMockForAbstractClass(GroupInterface::class);
85-
$groupMock->method('getId')
86-
->willReturn($defaultStoreId);
8777
$groupMock->expects($this->once())
8878
->method('getDefaultStoreId')
8979
->willReturn($defaultStoreId);

0 commit comments

Comments
 (0)