@@ -55,24 +55,31 @@ protected function setUp()
5555 * situation: one product is supplying the price, which could be a price of zero (0)
5656 *
5757 * @dataProvider resolvePriceDataProvider
58+ *
59+ * @param $variantPrices
60+ * @param $expectedPrice
5861 */
59- public function testResolvePrice ($ expectedValue )
62+ public function testResolvePrice ($ variantPrices , $ expectedPrice )
6063 {
61- $ price = $ expectedValue ;
62-
6364 $ product = $ this ->getMockBuilder (
6465 \Magento \Catalog \Model \Product::class
6566 )->disableOriginalConstructor ()->getMock ();
6667
6768 $ product ->expects ($ this ->never ())->method ('getSku ' );
6869
69- $ this ->lowestPriceOptionsProvider ->expects ($ this ->once ())->method ('getProducts ' )->willReturn ([$ product ]);
70- $ this ->priceResolver ->expects ($ this ->once ())
70+ $ products = array_map (function () {
71+ return $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
72+ ->disableOriginalConstructor ()
73+ ->getMock ();
74+ }, $ variantPrices );
75+
76+ $ this ->lowestPriceOptionsProvider ->expects ($ this ->once ())->method ('getProducts ' )->willReturn ($ products );
77+ $ this ->priceResolver
7178 ->method ('resolvePrice ' )
72- ->with ($ product )
73- ->willReturn ($ price );
79+ ->willReturnOnConsecutiveCalls (...$ variantPrices );
7480
75- $ this ->assertEquals ($ expectedValue , $ this ->resolver ->resolvePrice ($ product ));
81+ $ actualPrice = $ this ->resolver ->resolvePrice ($ product );
82+ self ::assertSame ($ expectedPrice , $ actualPrice );
7683 }
7784
7885 /**
@@ -81,8 +88,40 @@ public function testResolvePrice($expectedValue)
8188 public function resolvePriceDataProvider ()
8289 {
8390 return [
84- 'price of zero ' => [0.00 ],
85- 'price of five ' => [5 ],
91+ 'Single variant at price 0.00 (float), should return 0.00 (float) ' => [
92+ $ variantPrices = [
93+ 0.00 ,
94+ ],
95+ $ expectedPrice = 0.00 ,
96+ ],
97+ 'Single variant at price 5 (integer), should return 5.00 (float) ' => [
98+ $ variantPrices = [
99+ 5 ,
100+ ],
101+ $ expectedPrice = 5.00 ,
102+ ],
103+ 'Single variants at price null (null), should return 0.00 (float) ' => [
104+ $ variantPrices = [
105+ null ,
106+ ],
107+ $ expectedPrice = 0.00 ,
108+ ],
109+ 'Multiple variants at price 0, 10, 20, should return 0.00 (float) ' => [
110+ $ variantPrices = [
111+ 0 ,
112+ 10 ,
113+ 20 ,
114+ ],
115+ $ expectedPrice = 0.00 ,
116+ ],
117+ 'Multiple variants at price 10, 0, 20, should return 0.00 (float) ' => [
118+ $ variantPrices = [
119+ 10 ,
120+ 0 ,
121+ 20 ,
122+ ],
123+ $ expectedPrice = 0.00 ,
124+ ],
86125 ];
87126 }
88127}
0 commit comments