Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigurablePriceResolverTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class ConfigurablePriceResolverTest extends \PHPUnit\Framework\TestCase
12 {
16  private $lowestPriceOptionsProvider;
17 
21  protected $resolver;
22 
26  protected $configurable;
27 
31  protected $priceResolver;
32 
33  protected function setUp()
34  {
35  $className = \Magento\ConfigurableProduct\Model\Product\Type\Configurable::class;
36  $this->configurable = $this->createPartialMock($className, ['getUsedProducts']);
37 
38  $className = \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface::class;
39  $this->priceResolver = $this->getMockForAbstractClass($className, [], '', false, true, true, ['resolvePrice']);
40 
41  $this->lowestPriceOptionsProvider = $this->createMock(LowestPriceOptionsProviderInterface::class);
42 
43  $objectManager = new ObjectManager($this);
44  $this->resolver = $objectManager->getObject(
45  \Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver::class,
46  [
47  'priceResolver' => $this->priceResolver,
48  'configurable' => $this->configurable,
49  'lowestPriceOptionsProvider' => $this->lowestPriceOptionsProvider,
50  ]
51  );
52  }
53 
62  public function testResolvePrice($variantPrices, $expectedPrice)
63  {
64  $product = $this->getMockBuilder(
65  \Magento\Catalog\Model\Product::class
66  )->disableOriginalConstructor()->getMock();
67 
68  $product->expects($this->never())->method('getSku');
69 
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
78  ->method('resolvePrice')
79  ->willReturnOnConsecutiveCalls(...$variantPrices);
80 
81  $actualPrice = $this->resolver->resolvePrice($product);
82  self::assertSame($expectedPrice, $actualPrice);
83  }
84 
88  public function resolvePriceDataProvider()
89  {
90  return [
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  ],
125  ];
126  }
127 }
$objectManager
Definition: bootstrap.php:17
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31