7
7
8
8
namespace Magento \Catalog \Test \Unit \Model \Indexer \Product \Price \Action ;
9
9
10
+ use Magento \Framework \Indexer \DimensionalIndexerInterface ;
11
+ use Magento \Framework \Search \Request \Dimension ;
10
12
use Magento \Store \Model \StoreManagerInterface ;
11
13
use Magento \Directory \Model \CurrencyFactory ;
12
14
use Magento \Catalog \Model \Product \Type ;
@@ -94,36 +96,17 @@ class RowsTest extends TestCase
94
96
95
97
protected function setUp (): void
96
98
{
97
- $ this ->config = $ this ->getMockBuilder (ScopeConfigInterface::class)
98
- ->getMockForAbstractClass ();
99
- $ this ->storeManager = $ this ->getMockBuilder (StoreManagerInterface::class)
100
- ->getMockForAbstractClass ();
101
- $ this ->currencyFactory = $ this ->getMockBuilder (CurrencyFactory::class)
102
- ->disableOriginalConstructor ()
103
- ->getMock ();
104
- $ this ->localeDate = $ this ->getMockBuilder (TimezoneInterface::class)
105
- ->getMockForAbstractClass ();
106
- $ this ->dateTime = $ this ->getMockBuilder (DateTime::class)
107
- ->disableOriginalConstructor ()
108
- ->getMock ();
109
- $ this ->catalogProductType = $ this ->getMockBuilder (Type::class)
110
- ->disableOriginalConstructor ()
111
- ->getMock ();
112
- $ this ->indexerPriceFactory = $ this ->getMockBuilder (Factory::class)
113
- ->disableOriginalConstructor ()
114
- ->getMock ();
115
- $ this ->defaultIndexerResource = $ this ->getMockBuilder (DefaultPrice::class)
116
- ->disableOriginalConstructor ()
117
- ->getMock ();
118
- $ this ->tierPriceIndexResource = $ this ->getMockBuilder (TierPrice::class)
119
- ->disableOriginalConstructor ()
120
- ->getMock ();
121
- $ this ->dimensionCollectionFactory = $ this ->getMockBuilder (DimensionCollectionFactory::class)
122
- ->disableOriginalConstructor ()
123
- ->getMock ();
124
- $ this ->tableMaintainer = $ this ->getMockBuilder (TableMaintainer::class)
125
- ->disableOriginalConstructor ()
126
- ->getMock ();
99
+ $ this ->config = $ this ->createMock (ScopeConfigInterface::class);
100
+ $ this ->storeManager = $ this ->createMock (StoreManagerInterface::class);
101
+ $ this ->currencyFactory = $ this ->createMock (CurrencyFactory::class);
102
+ $ this ->localeDate = $ this ->createMock (TimezoneInterface::class);
103
+ $ this ->dateTime = $ this ->createMock (DateTime::class);
104
+ $ this ->catalogProductType = $ this ->createMock (Type::class);
105
+ $ this ->indexerPriceFactory = $ this ->createMock (Factory::class);
106
+ $ this ->defaultIndexerResource = $ this ->createMock (DefaultPrice::class);
107
+ $ this ->tierPriceIndexResource = $ this ->createMock (TierPrice::class);
108
+ $ this ->dimensionCollectionFactory = $ this ->createMock (DimensionCollectionFactory::class);
109
+ $ this ->tableMaintainer = $ this ->createMock (TableMaintainer::class);
127
110
$ batchSize = 2 ;
128
111
129
112
$ this ->actionRows = new Rows (
@@ -144,52 +127,72 @@ protected function setUp(): void
144
127
145
128
public function testEmptyIds ()
146
129
{
147
- $ this ->expectException (' Magento\Framework\Exception\InputException ' );
130
+ $ this ->expectException (\ Magento \Framework \Exception \InputException::class );
148
131
$ this ->expectExceptionMessage ('Bad value was supplied. ' );
149
132
$ this ->actionRows ->execute (null );
150
133
}
151
134
152
135
public function testBatchProcessing ()
153
136
{
154
137
$ ids = [1 , 2 , 3 , 4 ];
155
- $ select = $ this ->getMockBuilder (Select::class)
156
- ->disableOriginalConstructor ()
157
- ->getMock ();
158
- $ select ->expects ($ this ->any ())->method ('from ' )->willReturnSelf ();
159
- $ select ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
160
- $ select ->expects ($ this ->any ())->method ('join ' )->willReturnSelf ();
161
- $ adapter = $ this ->getMockBuilder (AdapterInterface::class)->getMockForAbstractClass ();
162
- $ adapter ->expects ($ this ->any ())->method ('select ' )->willReturn ($ select );
163
- $ this ->defaultIndexerResource ->expects ($ this ->any ())
164
- ->method ('getConnection ' )
165
- ->willReturn ($ adapter );
166
- $ adapter ->expects ($ this ->any ())
167
- ->method ('fetchAll ' )
168
- ->with ($ select )
169
- ->willReturn ([]);
170
- $ adapter ->expects ($ this ->any ())
138
+
139
+ $ select = $ this ->createMock (Select::class);
140
+ $ select ->method ('from ' )->willReturnSelf ();
141
+ $ select ->method ('joinLeft ' )->willReturnSelf ();
142
+ $ select ->method ('where ' )->willReturnSelf ();
143
+ $ select ->method ('join ' )->willReturnSelf ();
144
+ $ adapter = $ this ->createMock (AdapterInterface::class);
145
+ $ adapter ->method ('select ' )->willReturn ($ select );
146
+ $ adapter ->method ('describeTable ' )->willReturn ([]);
147
+ $ this ->defaultIndexerResource ->method ('getConnection ' )->willReturn ($ adapter );
148
+ $ adapter ->method ('fetchAll ' )->with ($ select )->willReturn ([]);
149
+
150
+ $ adapter ->expects ($ this ->exactly (4 ))
171
151
->method ('fetchPairs ' )
172
152
->with ($ select )
173
- ->willReturn ([]);
174
- $ multiDimensionProvider = $ this ->getMockBuilder (MultiDimensionProvider::class)
175
- ->disableOriginalConstructor ()
176
- ->getMock ();
177
- $ this ->dimensionCollectionFactory ->expects ($ this ->exactly (2 ))
153
+ ->willReturnOnConsecutiveCalls (
154
+ [1 => 'simple ' , 2 => 'virtual ' ],
155
+ [],
156
+ [3 => 'simple ' , 4 => 'virtual ' ],
157
+ [],
158
+ );
159
+ $ multiDimensionProvider = $ this ->createMock (MultiDimensionProvider::class);
160
+ $ this ->dimensionCollectionFactory ->expects ($ this ->exactly (4 ))
178
161
->method ('create ' )
179
162
->willReturn ($ multiDimensionProvider );
180
- $ iterator = new \ArrayIterator ([]);
181
- $ multiDimensionProvider ->expects ($ this ->exactly (2 ))
163
+ $ dimension = $ this ->createMock (Dimension::class);
164
+ $ dimension ->method ('getName ' )->willReturn ('default ' );
165
+ $ dimension ->method ('getValue ' )->willReturn ('0 ' );
166
+ $ iterator = new \ArrayIterator ([[$ dimension ]]);
167
+ $ multiDimensionProvider ->expects ($ this ->exactly (4 ))
182
168
->method ('getIterator ' )
183
169
->willReturn ($ iterator );
184
- $ this ->catalogProductType ->expects ($ this ->any ())
170
+ $ this ->catalogProductType ->expects ($ this ->once ())
185
171
->method ('getTypesByPriority ' )
186
- ->willReturn ([]);
172
+ ->willReturn (
173
+ [
174
+ 'virtual ' => ['price_indexer ' => '\Price\Indexer ' ],
175
+ 'simple ' => ['price_indexer ' => '\Price\Indexer ' ],
176
+ ]
177
+ );
178
+ $ priceIndexer = $ this ->createMock (DimensionalIndexerInterface::class);
179
+ $ this ->indexerPriceFactory ->expects ($ this ->exactly (2 ))
180
+ ->method ('create ' )
181
+ ->with ('\Price\Indexer ' , ['fullReindexAction ' => false ])
182
+ ->willReturn ($ priceIndexer );
183
+ $ priceIndexer ->expects ($ this ->exactly (4 ))
184
+ ->method ('executeByDimensions ' );
185
+ $ select ->expects ($ this ->exactly (4 ))
186
+ ->method ('deleteFromSelect ' )
187
+ ->with ('main_table ' )
188
+ ->willReturn ('' );
187
189
$ adapter ->expects ($ this ->exactly (2 ))
188
190
->method ('getIndexList ' )
189
191
->willReturn (['entity_id ' =>['COLUMNS_LIST ' =>['test ' ]]]);
190
192
$ adapter ->expects ($ this ->exactly (2 ))
191
193
->method ('getPrimaryKeyName ' )
192
194
->willReturn ('entity_id ' );
195
+
193
196
$ this ->actionRows ->execute ($ ids );
194
197
}
195
198
}
0 commit comments