Skip to content

Commit fa8dd0c

Browse files
committed
ACP2E-3761: Investigate if AC-6301 can be automated
1 parent d550808 commit fa8dd0c

File tree

2 files changed

+91
-9
lines changed

2 files changed

+91
-9
lines changed

app/code/Magento/CatalogInventory/Model/Indexer/Stock.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved
55
*/
66
namespace Magento\CatalogInventory\Model\Indexer;
77

88
use Magento\Framework\Indexer\CacheContext;
9+
use Magento\Framework\App\ObjectManager;
910

1011
class Stock implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
1112
{
1213
/**
13-
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Row
14+
* @var Row
1415
*/
1516
protected $_productStockIndexerRow;
1617

1718
/**
18-
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Rows
19+
* @var Rows
1920
*/
2021
protected $_productStockIndexerRows;
2122

2223
/**
23-
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Full
24+
* @var Full
2425
*/
2526
protected $_productStockIndexerFull;
2627

2728
/**
28-
* @var \Magento\Framework\Indexer\CacheContext
29+
* @var CacheContext
2930
*/
3031
private $cacheContext;
3132

3233
/**
3334
* @param Stock\Action\Row $productStockIndexerRow
3435
* @param Stock\Action\Rows $productStockIndexerRows
3536
* @param Stock\Action\Full $productStockIndexerFull
37+
* @param CacheContext|null $cacheContext
3638
*/
3739
public function __construct(
3840
\Magento\CatalogInventory\Model\Indexer\Stock\Action\Row $productStockIndexerRow,
3941
\Magento\CatalogInventory\Model\Indexer\Stock\Action\Rows $productStockIndexerRows,
40-
\Magento\CatalogInventory\Model\Indexer\Stock\Action\Full $productStockIndexerFull
42+
\Magento\CatalogInventory\Model\Indexer\Stock\Action\Full $productStockIndexerFull,
43+
?CacheContext $cacheContext = null
4144
) {
4245
$this->_productStockIndexerRow = $productStockIndexerRow;
4346
$this->_productStockIndexerRows = $productStockIndexerRows;
4447
$this->_productStockIndexerFull = $productStockIndexerFull;
48+
$this->cacheContext = $cacheContext ?: ObjectManager::getInstance()->get(CacheContext::class);
4549
}
4650

4751
/**
@@ -99,14 +103,14 @@ public function executeRow($id)
99103
/**
100104
* Get cache context
101105
*
102-
* @return \Magento\Framework\Indexer\CacheContext
106+
* @return CacheContext
103107
* @deprecated 100.0.7
104108
* @see we don't add dependecies this way anymore
105109
*/
106110
protected function getCacheContext()
107111
{
108112
if (!($this->cacheContext instanceof CacheContext)) {
109-
return \Magento\Framework\App\ObjectManager::getInstance()->get(CacheContext::class);
113+
return ObjectManager::getInstance()->get(CacheContext::class);
110114
} else {
111115
return $this->cacheContext;
112116
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventory\Test\Unit\Model\Indexer;
9+
10+
use Magento\CatalogInventory\Model\Indexer\Stock\Action\Row;
11+
use Magento\CatalogInventory\Model\Indexer\Stock\Action\Rows;
12+
use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full;
13+
use Magento\CatalogInventory\Model\Indexer\Stock;
14+
use Magento\Framework\Indexer\CacheContext;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class StockTest extends TestCase
19+
{
20+
/**
21+
* @var MockObject|Row
22+
*/
23+
private $productStockIndexerRow;
24+
25+
/**
26+
* @var MockObject|Rows
27+
*/
28+
private $productStockIndexerRows;
29+
30+
/**
31+
* @var MockObject|Full
32+
*/
33+
private $productStockIndexerFull;
34+
35+
/**
36+
* @var MockObject|CacheContext
37+
*/
38+
private $cacheContext;
39+
40+
/**
41+
* @var Stock
42+
*/
43+
private $stock;
44+
45+
/**
46+
* @inheritDoc
47+
*/
48+
protected function setUp(): void
49+
{
50+
$this->productStockIndexerRow = $this->createMock(Row::class);
51+
$this->productStockIndexerRows = $this->createMock(Rows::class);
52+
$this->productStockIndexerFull = $this->createMock(Full::class);
53+
$this->cacheContext = $this->createMock(CacheContext::class);
54+
55+
$this->stock = new Stock(
56+
$this->productStockIndexerRow,
57+
$this->productStockIndexerRows,
58+
$this->productStockIndexerFull,
59+
$this->cacheContext
60+
);
61+
}
62+
63+
/**
64+
* Validate that cache context not used during execution
65+
*
66+
* @return void
67+
*/
68+
public function testExecute(): void
69+
{
70+
$ids = [1, 2, 3];
71+
$this->productStockIndexerRows->expects($this->once())
72+
->method('execute')
73+
->with($ids);
74+
$this->cacheContext->expects($this->never())
75+
->method('registerEntities');
76+
$this->stock->execute($ids);
77+
}
78+
}

0 commit comments

Comments
 (0)