@@ -315,7 +315,7 @@ public function testPrepareForCartAdvancedWithShoppingCart()
315
315
->getMock ();
316
316
/** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */
317
317
$ selectionCollection = $ this ->getMockBuilder (\Magento \Bundle \Model \ResourceModel \Selection \Collection::class)
318
- ->setMethods (['getItems ' ])
318
+ ->setMethods (['getItems ' , ' getSize ' ])
319
319
->disableOriginalConstructor ()
320
320
->getMock ();
321
321
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */
@@ -430,6 +430,9 @@ function ($key) use ($optionCollection, $selectionCollection) {
430
430
$ selectionCollection ->expects ($ this ->any ())
431
431
->method ('getItems ' )
432
432
->willReturn ([$ selection ]);
433
+ $ selectionCollection ->expects ($ this ->any ())
434
+ ->method ('getSize ' )
435
+ ->willReturn (1 );
433
436
$ selection ->expects ($ this ->once ())
434
437
->method ('isSalable ' )
435
438
->willReturn (false );
@@ -556,7 +559,7 @@ public function testPrepareForCartAdvancedEmptyShoppingCart()
556
559
->getMock ();
557
560
/** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */
558
561
$ selectionCollection = $ this ->getMockBuilder (\Magento \Bundle \Model \ResourceModel \Selection \Collection::class)
559
- ->setMethods (['getItems ' ])
562
+ ->setMethods (['getItems ' , ' getSize ' ])
560
563
->disableOriginalConstructor ()
561
564
->getMock ();
562
565
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */
@@ -662,6 +665,9 @@ function ($key) use ($optionCollection, $selectionCollection) {
662
665
$ selectionCollection ->expects ($ this ->any ())
663
666
->method ('getItems ' )
664
667
->willReturn ([$ selection ]);
668
+ $ selectionCollection ->expects ($ this ->any ())
669
+ ->method ('getSize ' )
670
+ ->willReturn (1 );
665
671
$ selection ->expects ($ this ->once ())
666
672
->method ('isSalable ' )
667
673
->willReturn (false );
@@ -776,7 +782,7 @@ public function testPrepareForCartAdvancedStringInResult()
776
782
->getMock ();
777
783
/** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */
778
784
$ selectionCollection = $ this ->getMockBuilder (\Magento \Bundle \Model \ResourceModel \Selection \Collection::class)
779
- ->setMethods (['getItems ' ])
785
+ ->setMethods (['getItems ' , ' getSize ' ])
780
786
->disableOriginalConstructor ()
781
787
->getMock ();
782
788
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */
@@ -882,6 +888,9 @@ function ($key) use ($optionCollection, $selectionCollection) {
882
888
$ selectionCollection ->expects ($ this ->any ())
883
889
->method ('getItems ' )
884
890
->willReturn ([$ selection ]);
891
+ $ selectionCollection ->expects ($ this ->any ())
892
+ ->method ('getSize ' )
893
+ ->willReturn (1 );
885
894
$ selection ->expects ($ this ->once ())
886
895
->method ('isSalable ' )
887
896
->willReturn (false );
@@ -1078,7 +1087,7 @@ public function testPrepareForCartAdvancedSelectionsSelectionIdsExists()
1078
1087
->getMock ();
1079
1088
/** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */
1080
1089
$ selectionCollection = $ this ->getMockBuilder (\Magento \Bundle \Model \ResourceModel \Selection \Collection::class)
1081
- ->setMethods (['getItems ' ])
1090
+ ->setMethods (['getItems ' , ' getSize ' ])
1082
1091
->disableOriginalConstructor ()
1083
1092
->getMock ();
1084
1093
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */
@@ -1157,9 +1166,15 @@ function ($key) use ($optionCollection, $selectionCollection) {
1157
1166
$ selectionCollection ->expects ($ this ->at (0 ))
1158
1167
->method ('getItems ' )
1159
1168
->willReturn ([$ selection ]);
1169
+ $ selectionCollection ->expects ($ this ->at (0 ))
1170
+ ->method ('getSize ' )
1171
+ ->willReturn (1 );
1160
1172
$ selectionCollection ->expects ($ this ->at (1 ))
1161
1173
->method ('getItems ' )
1162
1174
->willReturn ([]);
1175
+ $ selectionCollection ->expects ($ this ->at (1 ))
1176
+ ->method ('getSize ' )
1177
+ ->willReturn (0 );
1163
1178
$ option ->expects ($ this ->any ())
1164
1179
->method ('getId ' )
1165
1180
->willReturn (3 );
@@ -1195,7 +1210,7 @@ public function testPrepareForCartAdvancedSelectRequiredOptions()
1195
1210
->getMock ();
1196
1211
/** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */
1197
1212
$ selectionCollection = $ this ->getMockBuilder (\Magento \Bundle \Model \ResourceModel \Selection \Collection::class)
1198
- ->setMethods (['getItems ' ])
1213
+ ->setMethods (['getItems ' , ' getSize ' ])
1199
1214
->disableOriginalConstructor ()
1200
1215
->getMock ();
1201
1216
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */
@@ -1275,6 +1290,9 @@ function ($key) use ($optionCollection, $selectionCollection) {
1275
1290
$ selectionCollection ->expects ($ this ->any ())
1276
1291
->method ('getItems ' )
1277
1292
->willReturn ([$ selection ]);
1293
+ $ selectionCollection ->expects ($ this ->any ())
1294
+ ->method ('getSize ' )
1295
+ ->willReturn (1 );
1278
1296
$ selection ->expects ($ this ->once ())
1279
1297
->method ('isSalable ' )
1280
1298
->willReturn (false );
@@ -2198,38 +2216,39 @@ public function testIsSalableWithEmptySelectionsCollection()
2198
2216
/**
2199
2217
* @return void
2200
2218
*/
2201
- public function nottestIsSalableWithRequiredOptionsOutOfStock ()
2219
+ public function testIsSalableWithNonSalableRequiredOptions ()
2202
2220
{
2203
2221
$ option1 = $ this ->getRequiredOptionMock (10 , 10 );
2204
- $ option1
2205
- ->expects ($ this ->atLeastOnce ())
2206
- ->method ('getSelectionCanChangeQty ' )
2207
- ->willReturn (false );
2208
-
2209
2222
$ option2 = $ this ->getRequiredOptionMock (20 , 10 );
2210
- $ option2
2211
- ->expects ($ this ->atLeastOnce ())
2212
- ->method ('getSelectionCanChangeQty ' )
2223
+ $ optionCollectionMock = $ this ->getOptionCollectionMock ([$ option1 , $ option2 ]);
2224
+
2225
+ $ selection1 = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
2226
+ ->setMethods (['isSalable ' ])
2227
+ ->disableOriginalConstructor ()
2228
+ ->getMock ();
2229
+
2230
+ $ selection1 ->expects ($ this ->once ())
2231
+ ->method ('isSalable ' )
2232
+ ->willReturn (true );
2233
+
2234
+ $ selection2 = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
2235
+ ->setMethods (['isSalable ' ])
2236
+ ->disableOriginalConstructor ()
2237
+ ->getMock ();
2238
+
2239
+ $ selection2 ->expects ($ this ->once ())
2240
+ ->method ('isSalable ' )
2213
2241
->willReturn (false );
2214
2242
2215
- $ this ->stockRegistry ->method ('getStockItem ' )
2216
- ->willReturn ($ this ->getStockItem (true ));
2217
- $ this ->stockState
2218
- ->method ('getStockQty ' )
2219
- ->will (
2220
- $ this ->returnValueMap (
2221
- [
2222
- [10 , 10 ],
2223
- [20 , 5 ]
2224
- ]
2225
- )
2226
- );
2243
+ $ selectionCollectionMock1 = $ this ->getSelectionCollectionMock ([$ selection1 ]);
2244
+ $ selectionCollectionMock2 = $ this ->getSelectionCollectionMock ([$ selection2 ]);
2227
2245
2228
- $ optionCollectionMock = $ this ->getOptionCollectionMock ([$ option1 , $ option2 ]);
2229
- $ selectionCollectionMock = $ this ->getSelectionCollectionMock ([$ option1 , $ option2 ]);
2230
- $ this ->bundleCollection ->expects ($ this ->once ())
2246
+ $ this ->bundleCollection ->expects ($ this ->exactly (2 ))
2231
2247
->method ('create ' )
2232
- ->will ($ this ->returnValue ($ selectionCollectionMock ));
2248
+ ->will ($ this ->onConsecutiveCalls (
2249
+ $ selectionCollectionMock1 ,
2250
+ $ selectionCollectionMock2
2251
+ ));
2233
2252
2234
2253
$ product = new \Magento \Framework \DataObject (
2235
2254
[
@@ -2289,14 +2308,8 @@ private function getSelectionCollectionMock(array $selectedOptions)
2289
2308
{
2290
2309
$ selectionCollectionMock = $ this ->getMockBuilder (
2291
2310
\Magento \Bundle \Model \ResourceModel \Selection \Collection::class
2292
- )
2293
- ->disableOriginalConstructor ()
2294
- ->getMock ();
2295
-
2296
- $ selectionCollectionMock
2297
- ->expects ($ this ->any ())
2298
- ->method ('getItems ' )
2299
- ->willReturn ($ selectedOptions );
2311
+ )->disableOriginalConstructor ()
2312
+ ->getMock ();
2300
2313
2301
2314
$ selectionCollectionMock
2302
2315
->expects ($ this ->any ())
@@ -2312,25 +2325,14 @@ private function getSelectionCollectionMock(array $selectedOptions)
2312
2325
*/
2313
2326
private function getOptionCollectionMock (array $ options )
2314
2327
{
2315
- $ ids = [];
2316
- foreach ($ options as $ option ) {
2317
- $ ids [] = $ option ->getId ();
2318
- }
2319
-
2320
2328
$ optionCollectionMock = $ this ->getMockBuilder (\Magento \Bundle \Model \ResourceModel \Option \Collection::class)
2321
- ->setMethods (['getItems ' , ' getAllIds ' ])
2329
+ ->setMethods (['getIterator ' ])
2322
2330
->disableOriginalConstructor ()
2323
2331
->getMock ();
2324
2332
2325
- $ optionCollectionMock
2326
- ->expects ($ this ->any ())
2327
- ->method ('getItems ' )
2328
- ->willReturn ($ options );
2329
-
2330
- $ optionCollectionMock
2331
- ->expects ($ this ->any ())
2332
- ->method ('getAllIds ' )
2333
- ->willReturn ($ ids );
2333
+ $ optionCollectionMock ->expects ($ this ->any ())
2334
+ ->method ('getIterator ' )
2335
+ ->will ($ this ->returnValue (new \ArrayIterator ($ options )));
2334
2336
2335
2337
return $ optionCollectionMock ;
2336
2338
}
@@ -2560,7 +2562,7 @@ public function testHasOptions()
2560
2562
$ selectionCollection = $ this ->getSelectionCollection ();
2561
2563
$ selectionCollection
2562
2564
->expects ($ this ->any ())
2563
- ->method ('count ' )
2565
+ ->method ('getSize ' )
2564
2566
->willReturn (1 );
2565
2567
$ this ->bundleCollection ->expects ($ this ->once ())->method ('create ' )->willReturn ($ selectionCollection );
2566
2568
0 commit comments