8
8
use Magento \CatalogInventory \Model \Quote \Item \QuantityValidator \QuoteItemQtyList ;
9
9
10
10
/**
11
+ * Class StockItemTest
11
12
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
13
*/
13
14
class StockItemTest extends \PHPUnit \Framework \TestCase
@@ -28,10 +29,18 @@ class StockItemTest extends \PHPUnit\Framework\TestCase
28
29
protected $ typeConfig ;
29
30
30
31
/**
31
- * @var \PHPUnit_Framework_MockObject_MockObject
32
+ * @var \Magento\CatalogInventory\Api\StockStateInterface\ PHPUnit_Framework_MockObject_MockObject
32
33
*/
33
34
protected $ stockStateMock ;
34
35
36
+ /**
37
+ * @var \Magento\CatalogInventory\Model\StockStateProviderInterface| \PHPUnit_Framework_MockObject_MockObject
38
+ */
39
+ private $ stockStateProviderMock ;
40
+
41
+ /**
42
+ * @inheritdoc
43
+ */
35
44
protected function setUp ()
36
45
{
37
46
$ this ->quoteItemQtyList = $ this
@@ -48,17 +57,25 @@ protected function setUp()
48
57
$ this ->stockStateMock = $ this ->getMockBuilder (\Magento \CatalogInventory \Api \StockStateInterface::class)
49
58
->disableOriginalConstructor ()
50
59
->getMock ();
60
+
61
+ $ this ->stockStateProviderMock = $ this
62
+ ->getMockBuilder (\Magento \CatalogInventory \Model \StockStateProvider::class)
63
+ ->disableOriginalConstructor ()
64
+ ->getMock ();
65
+
51
66
$ this ->model = $ objectManagerHelper ->getObject (
52
67
\Magento \CatalogInventory \Model \Quote \Item \QuantityValidator \Initializer \StockItem::class,
53
68
[
54
69
'quoteItemQtyList ' => $ this ->quoteItemQtyList ,
55
70
'typeConfig ' => $ this ->typeConfig ,
56
- 'stockState ' => $ this ->stockStateMock
71
+ 'stockState ' => $ this ->stockStateMock ,
72
+ 'stockStateProvider ' => $ this ->stockStateProviderMock
57
73
]
58
74
);
59
75
}
60
76
61
77
/**
78
+ * Test initialize with Subitem
62
79
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
63
80
*/
64
81
public function testInitializeWithSubitem ()
@@ -141,6 +158,10 @@ public function testInitializeWithSubitem()
141
158
->method ('checkQuoteItemQty ' )
142
159
->withAnyParameters ()
143
160
->will ($ this ->returnValue ($ result ));
161
+ $ this ->stockStateProviderMock ->expects ($ this ->once ())
162
+ ->method ('checkQuoteItemQty ' )
163
+ ->withAnyParameters ()
164
+ ->will ($ this ->returnValue ($ result ));
144
165
$ product ->expects ($ this ->once ())
145
166
->method ('getCustomOption ' )
146
167
->with ('product_type ' )
@@ -177,13 +198,16 @@ public function testInitializeWithSubitem()
177
198
$ quoteItem ->expects ($ this ->once ())->method ('setUseOldQty ' )->with ('item ' )->will ($ this ->returnSelf ());
178
199
$ result ->expects ($ this ->exactly (2 ))->method ('getMessage ' )->will ($ this ->returnValue ('message ' ));
179
200
$ quoteItem ->expects ($ this ->once ())->method ('setMessage ' )->with ('message ' )->will ($ this ->returnSelf ());
180
- $ result ->expects ($ this ->exactly (2 ))->method ('getItemBackorders ' )->will ($ this ->returnValue ('backorders ' ));
201
+ $ result ->expects ($ this ->exactly (3 ))->method ('getItemBackorders ' )->will ($ this ->returnValue ('backorders ' ));
181
202
$ quoteItem ->expects ($ this ->once ())->method ('setBackorders ' )->with ('backorders ' )->will ($ this ->returnSelf ());
182
203
$ quoteItem ->expects ($ this ->once ())->method ('setStockStateResult ' )->with ($ result )->will ($ this ->returnSelf ());
183
204
184
205
$ this ->model ->initialize ($ stockItem , $ quoteItem , $ qty );
185
206
}
186
207
208
+ /**
209
+ * Test initialize without Subitem
210
+ */
187
211
public function testInitializeWithoutSubitem ()
188
212
{
189
213
$ qty = 3 ;
@@ -234,6 +258,10 @@ public function testInitializeWithoutSubitem()
234
258
->with ($ productId , 'quote_item_id ' , 'quote_id ' , $ qty )
235
259
->will ($ this ->returnValue ('summary_qty ' ));
236
260
$ this ->stockStateMock ->expects ($ this ->once ())
261
+ ->method ('checkQuoteItemQty ' )
262
+ ->withAnyParameters ()
263
+ ->will ($ this ->returnValue ($ result ));
264
+ $ this ->stockStateProviderMock ->expects ($ this ->once ())
237
265
->method ('checkQuoteItemQty ' )
238
266
->withAnyParameters ()
239
267
->will ($ this ->returnValue ($ result ));
@@ -256,7 +284,7 @@ public function testInitializeWithoutSubitem()
256
284
$ result ->expects ($ this ->once ())->method ('getHasQtyOptionUpdate ' )->will ($ this ->returnValue (false ));
257
285
$ result ->expects ($ this ->once ())->method ('getItemUseOldQty ' )->will ($ this ->returnValue (null ));
258
286
$ result ->expects ($ this ->once ())->method ('getMessage ' )->will ($ this ->returnValue (null ));
259
- $ result ->expects ($ this ->once ( ))->method ('getItemBackorders ' )->will ($ this ->returnValue (null ));
287
+ $ result ->expects ($ this ->exactly ( 2 ))->method ('getItemBackorders ' )->will ($ this ->returnValue (null ));
260
288
261
289
$ this ->model ->initialize ($ stockItem , $ quoteItem , $ qty );
262
290
}
0 commit comments