66
77namespace Magento \CatalogInventory \Test \Unit \Model \Quote \Item \QuantityValidator \Initializer ;
88
9+ use Magento \CatalogInventory \Api \Data \StockStatusInterface ;
10+ use Magento \CatalogInventory \Model \Stock \Status ;
911use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1012use Magento \CatalogInventory \Model \StockRegistry ;
1113use Magento \CatalogInventory \Model \Quote \Item \QuantityValidator \Initializer \Option ;
@@ -112,10 +114,25 @@ class QuantityValidatorTest extends \PHPUnit_Framework_TestCase
112114 */
113115 private $ stockItemInitializer ;
114116
117+ /**
118+ * @var \PHPUnit_Framework_MockObject_MockObject|StockStatusInterface
119+ */
120+ private $ stockStatusMock ;
121+
115122 protected function setUp ()
116123 {
117124 $ objectManagerHelper = new ObjectManager ($ this );
118- $ this ->stockRegistryMock = $ this ->getMock (StockRegistry::class, ['getStockItem ' ], [], '' , false );
125+
126+ $ this ->stockRegistryMock = $ this ->getMock (
127+ StockRegistry::class,
128+ [],
129+ [],
130+ '' ,
131+ false
132+ );
133+
134+ $ this ->stockStatusMock = $ this ->getMock (Status::class, [], [], '' , false );
135+
119136 $ this ->optionInitializer = $ this ->getMock (Option::class, [], [], '' , false );
120137 $ this ->stockItemInitializer = $ this ->getMock (StockItem::class, [], [], '' , false );
121138 $ this ->stockState = $ this ->getMock (StockState::class, [], [], '' , false );
@@ -149,8 +166,10 @@ protected function setUp()
149166 );
150167 $ this ->productMock = $ this ->getMock (Product::class, [], [], '' , false );
151168 $ this ->stockItemMock = $ this ->getMock (StockMock::class, [], [], '' , false );
152- $ this ->parentStockItemMock = $ this ->getMock (StockMock::class, [], [], '' , false );
169+ $ this ->parentStockItemMock = $ this ->getMock (StockMock::class, ['getStockStatus ' ], [], '' , false );
170+
153171 $ this ->typeInstanceMock = $ this ->getMock (Type::class, [], [], '' , false );
172+
154173 $ this ->resultMock = $ this ->getMock (
155174 DataObject::class,
156175 ['checkQtyIncrements ' , 'getMessage ' , 'getQuoteMessage ' , 'getHasError ' ],
@@ -171,9 +190,11 @@ public function testValidateOutOfStock()
171190 $ this ->stockRegistryMock ->expects ($ this ->at (0 ))
172191 ->method ('getStockItem ' )
173192 ->willReturn ($ this ->stockItemMock );
174- $ this ->stockItemMock ->expects ($ this ->once ())
175- ->method ('getIsInStock ' )
176- ->willReturn (false );
193+
194+ $ this ->stockRegistryMock ->expects ($ this ->atLeastOnce ())
195+ ->method ('getStockStatus ' )
196+ ->willReturn ($ this ->stockStatusMock );
197+
177198 $ this ->quoteItemMock ->expects ($ this ->once ())
178199 ->method ('addErrorInfo ' )
179200 ->with (
@@ -203,21 +224,27 @@ public function testValidateInStock()
203224 $ this ->stockRegistryMock ->expects ($ this ->at (0 ))
204225 ->method ('getStockItem ' )
205226 ->willReturn ($ this ->stockItemMock );
227+
206228 $ this ->stockRegistryMock ->expects ($ this ->at (1 ))
207- ->method ('getStockItem ' )
208- ->willReturn ($ this ->parentStockItemMock );
209- $ this ->parentStockItemMock ->expects ($ this ->once ())
210- ->method ('getIsInStock ' )
211- ->willReturn (false );
229+ ->method ('getStockStatus ' )
230+ ->willReturn ($ this ->stockStatusMock );
231+
212232 $ this ->quoteItemMock ->expects ($ this ->any ())
213233 ->method ('getParentItem ' )
214234 ->willReturn ($ this ->parentItemMock );
215- $ this ->stockItemMock ->expects ($ this ->once ())
216- ->method ('getIsInStock ' )
235+
236+ $ this ->stockRegistryMock ->expects ($ this ->at (2 ))
237+ ->method ('getStockStatus ' )
238+ ->willReturn ($ this ->parentStockItemMock );
239+
240+ $ this ->parentStockItemMock ->expects ($ this ->once ())
241+ ->method ('getStockStatus ' )
242+ ->willReturn (false );
243+
244+ $ this ->stockStatusMock ->expects ($ this ->atLeastOnce ())
245+ ->method ('getStockStatus ' )
217246 ->willReturn (true );
218- $ this ->stockRegistryMock ->expects ($ this ->at (0 ))
219- ->method ('getStockItem ' )
220- ->willReturn ($ this ->stockItemMock );
247+
221248 $ this ->quoteItemMock ->expects ($ this ->once ())
222249 ->method ('addErrorInfo ' )
223250 ->with (
@@ -250,15 +277,18 @@ public function testValidateWithOptions()
250277 $ this ->stockRegistryMock ->expects ($ this ->at (0 ))
251278 ->method ('getStockItem ' )
252279 ->willReturn ($ this ->stockItemMock );
280+ $ this ->stockRegistryMock ->expects ($ this ->at (1 ))
281+ ->method ('getStockStatus ' )
282+ ->willReturn ($ this ->stockStatusMock );
253283 $ options = [$ optionMock ];
254284 $ this ->createInitialStub (1 );
255285 $ this ->setUpStubForQuantity (1 , true );
256286 $ this ->setUpStubForRemoveError ();
257287 $ this ->parentStockItemMock ->expects ($ this ->any ())
258- ->method ('getIsInStock ' )
288+ ->method ('getStockStatus ' )
259289 ->willReturn (true );
260- $ this ->stockItemMock ->expects ($ this ->once ())
261- ->method ('getIsInStock ' )
290+ $ this ->stockStatusMock ->expects ($ this ->once ())
291+ ->method ('getStockStatus ' )
262292 ->willReturn (true );
263293 $ this ->quoteItemMock ->expects ($ this ->any ())
264294 ->method ('getQtyOptions ' )
@@ -285,15 +315,18 @@ public function testValidateWithOptionsAndError()
285315 $ this ->stockRegistryMock ->expects ($ this ->at (0 ))
286316 ->method ('getStockItem ' )
287317 ->willReturn ($ this ->stockItemMock );
318+ $ this ->stockRegistryMock ->expects ($ this ->at (1 ))
319+ ->method ('getStockStatus ' )
320+ ->willReturn ($ this ->stockStatusMock );
288321 $ options = [$ optionMock ];
289322 $ this ->createInitialStub (1 );
290323 $ this ->setUpStubForQuantity (1 , true );
291324 $ this ->setUpStubForRemoveError ();
292325 $ this ->parentStockItemMock ->expects ($ this ->any ())
293- ->method ('getIsInStock ' )
326+ ->method ('getStockStatus ' )
294327 ->willReturn (true );
295- $ this ->stockItemMock ->expects ($ this ->once ())
296- ->method ('getIsInStock ' )
328+ $ this ->stockStatusMock ->expects ($ this ->once ())
329+ ->method ('getStockStatus ' )
297330 ->willReturn (true );
298331 $ this ->quoteItemMock ->expects ($ this ->any ())
299332 ->method ('getQtyOptions ' )
@@ -321,11 +354,14 @@ public function testRemoveError()
321354 $ this ->stockRegistryMock ->expects ($ this ->at (0 ))
322355 ->method ('getStockItem ' )
323356 ->willReturn ($ this ->stockItemMock );
357+ $ this ->stockRegistryMock ->expects ($ this ->at (1 ))
358+ ->method ('getStockStatus ' )
359+ ->willReturn ($ this ->stockStatusMock );
324360 $ this ->quoteItemMock ->expects ($ this ->any ())
325361 ->method ('getParentItem ' )
326362 ->willReturn ($ this ->parentItemMock );
327- $ this ->stockItemMock ->expects ($ this ->once ())
328- ->method ('getIsInStock ' )
363+ $ this ->stockStatusMock ->expects ($ this ->once ())
364+ ->method ('getStockStatus ' )
329365 ->willReturn (true );
330366 $ this ->quoteItemMock ->expects ($ this ->never ())
331367 ->method ('addErrorInfo ' );
0 commit comments