@@ -55,24 +55,31 @@ protected function setUp()
55
55
* situation: one product is supplying the price, which could be a price of zero (0)
56
56
*
57
57
* @dataProvider resolvePriceDataProvider
58
+ *
59
+ * @param $variantPrices
60
+ * @param $expectedPrice
58
61
*/
59
- public function testResolvePrice ($ expectedValue )
62
+ public function testResolvePrice ($ variantPrices , $ expectedPrice )
60
63
{
61
- $ price = $ expectedValue ;
62
-
63
64
$ product = $ this ->getMockBuilder (
64
65
\Magento \Catalog \Model \Product::class
65
66
)->disableOriginalConstructor ()->getMock ();
66
67
67
68
$ product ->expects ($ this ->never ())->method ('getSku ' );
68
69
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
71
78
->method ('resolvePrice ' )
72
- ->with ($ product )
73
- ->willReturn ($ price );
79
+ ->willReturnOnConsecutiveCalls (...$ variantPrices );
74
80
75
- $ this ->assertEquals ($ expectedValue , $ this ->resolver ->resolvePrice ($ product ));
81
+ $ actualPrice = $ this ->resolver ->resolvePrice ($ product );
82
+ self ::assertSame ($ expectedPrice , $ actualPrice );
76
83
}
77
84
78
85
/**
@@ -81,8 +88,40 @@ public function testResolvePrice($expectedValue)
81
88
public function resolvePriceDataProvider ()
82
89
{
83
90
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
+ ],
86
125
];
87
126
}
88
127
}
0 commit comments