5
5
*/
6
6
namespace Magento \ConfigurableProduct \Test \Unit \Block \Product \View \Type ;
7
7
8
+ /**
9
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10
+ */
8
11
class ConfigurableTestTest extends \PHPUnit_Framework_TestCase
9
12
{
10
13
/**
@@ -128,18 +131,7 @@ public function testGetJsonConfig()
128
131
$ priceQty = 1 ;
129
132
$ percentage = 10 ;
130
133
131
- $ amountMock = $ this ->getMockBuilder (\Magento \Framework \Pricing \Amount \AmountInterface::class)
132
- ->setMethods ([
133
- 'getValue ' ,
134
- 'getBaseAmount ' ,
135
- ])
136
- ->getMockForAbstractClass ();
137
- $ amountMock ->expects ($ this ->any ())
138
- ->method ('getValue ' )
139
- ->willReturn ($ amount );
140
- $ amountMock ->expects ($ this ->any ())
141
- ->method ('getBaseAmount ' )
142
- ->willReturn ($ amount );
134
+ $ amountMock = $ this ->getAmountMock ($ amount );
143
135
144
136
$ priceMock = $ this ->getMockBuilder (\Magento \Framework \Pricing \Price \PriceInterface::class)
145
137
->setMethods ([
@@ -150,23 +142,7 @@ public function testGetJsonConfig()
150
142
->method ('getAmount ' )
151
143
->willReturn ($ amountMock );
152
144
153
- $ tierPrice = [
154
- 'price_qty ' => $ priceQty ,
155
- 'price ' => $ amountMock ,
156
- ];
157
-
158
- $ tierPriceMock = $ this ->getMockBuilder (\Magento \Catalog \Pricing \Price \TierPriceInterface::class)
159
- ->setMethods ([
160
- 'getTierPriceList ' ,
161
- 'getSavePercent ' ,
162
- ])
163
- ->getMockForAbstractClass ();
164
- $ tierPriceMock ->expects ($ this ->any ())
165
- ->method ('getTierPriceList ' )
166
- ->willReturn ([$ tierPrice ]);
167
- $ tierPriceMock ->expects ($ this ->any ())
168
- ->method ('getSavePercent ' )
169
- ->willReturn ($ percentage );
145
+ $ tierPriceMock = $ this ->getTierPriceMock ($ amountMock , $ priceQty , $ percentage );
170
146
171
147
$ productMock = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
172
148
->disableOriginalConstructor ()
@@ -368,4 +344,59 @@ protected function mockContextObject()
368
344
->method ('getRegistry ' )
369
345
->willReturn ($ this ->registry );
370
346
}
347
+
348
+ /**
349
+ * Retrieve mock of \Magento\Framework\Pricing\Amount\AmountInterface object
350
+ *
351
+ * @param float $amount
352
+ * @return \PHPUnit_Framework_MockObject_MockObject
353
+ */
354
+ protected function getAmountMock ($ amount ): \PHPUnit_Framework_MockObject_MockObject
355
+ {
356
+ $ amountMock = $ this ->getMockBuilder (\Magento \Framework \Pricing \Amount \AmountInterface::class)
357
+ ->setMethods ([
358
+ 'getValue ' ,
359
+ 'getBaseAmount ' ,
360
+ ])
361
+ ->getMockForAbstractClass ();
362
+ $ amountMock ->expects ($ this ->any ())
363
+ ->method ('getValue ' )
364
+ ->willReturn ($ amount );
365
+ $ amountMock ->expects ($ this ->any ())
366
+ ->method ('getBaseAmount ' )
367
+ ->willReturn ($ amount );
368
+
369
+ return $ amountMock ;
370
+ }
371
+
372
+ /**
373
+ * Retrieve mock of \Magento\Catalog\Pricing\Price\TierPriceInterface object
374
+ *
375
+ * @param \PHPUnit_Framework_MockObject_MockObject $amountMock
376
+ * @param float $priceQty
377
+ * @param int $percentage
378
+ * @return \PHPUnit_Framework_MockObject_MockObject
379
+ */
380
+ protected function getTierPriceMock (\PHPUnit_Framework_MockObject_MockObject $ amountMock , $ priceQty , $ percentage )
381
+ {
382
+ $ tierPrice = [
383
+ 'price_qty ' => $ priceQty ,
384
+ 'price ' => $ amountMock ,
385
+ ];
386
+
387
+ $ tierPriceMock = $ this ->getMockBuilder (\Magento \Catalog \Pricing \Price \TierPriceInterface::class)
388
+ ->setMethods ([
389
+ 'getTierPriceList ' ,
390
+ 'getSavePercent ' ,
391
+ ])
392
+ ->getMockForAbstractClass ();
393
+ $ tierPriceMock ->expects ($ this ->any ())
394
+ ->method ('getTierPriceList ' )
395
+ ->willReturn ([$ tierPrice ]);
396
+ $ tierPriceMock ->expects ($ this ->any ())
397
+ ->method ('getSavePercent ' )
398
+ ->willReturn ($ percentage );
399
+
400
+ return $ tierPriceMock ;
401
+ }
371
402
}
0 commit comments