6
6
7
7
namespace Magento \CatalogInventory \Test \Unit \Model \Quote \Item \QuantityValidator \Initializer ;
8
8
9
+ use Magento \CatalogInventory \Api \Data \StockStatusInterface ;
10
+ use Magento \CatalogInventory \Model \Stock \Status ;
9
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
12
use Magento \CatalogInventory \Model \StockRegistry ;
11
13
use Magento \CatalogInventory \Model \Quote \Item \QuantityValidator \Initializer \Option ;
@@ -112,10 +114,25 @@ class QuantityValidatorTest extends \PHPUnit_Framework_TestCase
112
114
*/
113
115
private $ stockItemInitializer ;
114
116
117
+ /**
118
+ * @var \PHPUnit_Framework_MockObject_MockObject|StockStatusInterface
119
+ */
120
+ private $ stockStatusMock ;
121
+
115
122
protected function setUp ()
116
123
{
117
124
$ 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
+
119
136
$ this ->optionInitializer = $ this ->getMock (Option::class, [], [], '' , false );
120
137
$ this ->stockItemInitializer = $ this ->getMock (StockItem::class, [], [], '' , false );
121
138
$ this ->stockState = $ this ->getMock (StockState::class, [], [], '' , false );
@@ -149,8 +166,10 @@ protected function setUp()
149
166
);
150
167
$ this ->productMock = $ this ->getMock (Product::class, [], [], '' , false );
151
168
$ 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
+
153
171
$ this ->typeInstanceMock = $ this ->getMock (Type::class, [], [], '' , false );
172
+
154
173
$ this ->resultMock = $ this ->getMock (
155
174
DataObject::class,
156
175
['checkQtyIncrements ' , 'getMessage ' , 'getQuoteMessage ' , 'getHasError ' ],
@@ -171,9 +190,11 @@ public function testValidateOutOfStock()
171
190
$ this ->stockRegistryMock ->expects ($ this ->at (0 ))
172
191
->method ('getStockItem ' )
173
192
->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
+
177
198
$ this ->quoteItemMock ->expects ($ this ->once ())
178
199
->method ('addErrorInfo ' )
179
200
->with (
@@ -203,21 +224,27 @@ public function testValidateInStock()
203
224
$ this ->stockRegistryMock ->expects ($ this ->at (0 ))
204
225
->method ('getStockItem ' )
205
226
->willReturn ($ this ->stockItemMock );
227
+
206
228
$ 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
+
212
232
$ this ->quoteItemMock ->expects ($ this ->any ())
213
233
->method ('getParentItem ' )
214
234
->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 ' )
217
246
->willReturn (true );
218
- $ this ->stockRegistryMock ->expects ($ this ->at (0 ))
219
- ->method ('getStockItem ' )
220
- ->willReturn ($ this ->stockItemMock );
247
+
221
248
$ this ->quoteItemMock ->expects ($ this ->once ())
222
249
->method ('addErrorInfo ' )
223
250
->with (
@@ -250,15 +277,18 @@ public function testValidateWithOptions()
250
277
$ this ->stockRegistryMock ->expects ($ this ->at (0 ))
251
278
->method ('getStockItem ' )
252
279
->willReturn ($ this ->stockItemMock );
280
+ $ this ->stockRegistryMock ->expects ($ this ->at (1 ))
281
+ ->method ('getStockStatus ' )
282
+ ->willReturn ($ this ->stockStatusMock );
253
283
$ options = [$ optionMock ];
254
284
$ this ->createInitialStub (1 );
255
285
$ this ->setUpStubForQuantity (1 , true );
256
286
$ this ->setUpStubForRemoveError ();
257
287
$ this ->parentStockItemMock ->expects ($ this ->any ())
258
- ->method ('getIsInStock ' )
288
+ ->method ('getStockStatus ' )
259
289
->willReturn (true );
260
- $ this ->stockItemMock ->expects ($ this ->once ())
261
- ->method ('getIsInStock ' )
290
+ $ this ->stockStatusMock ->expects ($ this ->once ())
291
+ ->method ('getStockStatus ' )
262
292
->willReturn (true );
263
293
$ this ->quoteItemMock ->expects ($ this ->any ())
264
294
->method ('getQtyOptions ' )
@@ -285,15 +315,18 @@ public function testValidateWithOptionsAndError()
285
315
$ this ->stockRegistryMock ->expects ($ this ->at (0 ))
286
316
->method ('getStockItem ' )
287
317
->willReturn ($ this ->stockItemMock );
318
+ $ this ->stockRegistryMock ->expects ($ this ->at (1 ))
319
+ ->method ('getStockStatus ' )
320
+ ->willReturn ($ this ->stockStatusMock );
288
321
$ options = [$ optionMock ];
289
322
$ this ->createInitialStub (1 );
290
323
$ this ->setUpStubForQuantity (1 , true );
291
324
$ this ->setUpStubForRemoveError ();
292
325
$ this ->parentStockItemMock ->expects ($ this ->any ())
293
- ->method ('getIsInStock ' )
326
+ ->method ('getStockStatus ' )
294
327
->willReturn (true );
295
- $ this ->stockItemMock ->expects ($ this ->once ())
296
- ->method ('getIsInStock ' )
328
+ $ this ->stockStatusMock ->expects ($ this ->once ())
329
+ ->method ('getStockStatus ' )
297
330
->willReturn (true );
298
331
$ this ->quoteItemMock ->expects ($ this ->any ())
299
332
->method ('getQtyOptions ' )
@@ -321,11 +354,14 @@ public function testRemoveError()
321
354
$ this ->stockRegistryMock ->expects ($ this ->at (0 ))
322
355
->method ('getStockItem ' )
323
356
->willReturn ($ this ->stockItemMock );
357
+ $ this ->stockRegistryMock ->expects ($ this ->at (1 ))
358
+ ->method ('getStockStatus ' )
359
+ ->willReturn ($ this ->stockStatusMock );
324
360
$ this ->quoteItemMock ->expects ($ this ->any ())
325
361
->method ('getParentItem ' )
326
362
->willReturn ($ this ->parentItemMock );
327
- $ this ->stockItemMock ->expects ($ this ->once ())
328
- ->method ('getIsInStock ' )
363
+ $ this ->stockStatusMock ->expects ($ this ->once ())
364
+ ->method ('getStockStatus ' )
329
365
->willReturn (true );
330
366
$ this ->quoteItemMock ->expects ($ this ->never ())
331
367
->method ('addErrorInfo ' );
0 commit comments