Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BundlePriceTest.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterfaceFactory;
17 
18 class BundlePriceTest extends \PHPUnit\Framework\TestCase
19 {
23  private $model;
24 
28  private $priceCurrencyMock;
29 
33  private $priceInfoFactory;
34 
38  private $formattedPriceInfoBuilder;
39 
40  public function setUp()
41  {
42  $this->priceCurrencyMock = $this->getMockBuilder(PriceCurrencyInterface::class)
43  ->getMockForAbstractClass();
44  $this->priceInfoFactory = $this->getMockBuilder(PriceInfoInterfaceFactory::class)
45  ->disableOriginalConstructor()
46  ->setMethods(['create'])
47  ->getMock();
48  $this->formattedPriceInfoBuilder = $this->getMockBuilder(FormattedPriceInfoBuilder::class)
49  ->disableOriginalConstructor()
50  ->getMock();
51 
52  $this->model = new BundlePrice(
53  $this->priceCurrencyMock,
54  $this->priceInfoFactory,
55  $this->formattedPriceInfoBuilder
56  );
57  }
58 
59  public function testCollect()
60  {
61  $minAmountValue = 5;
62  $amountValue = 10;
63  $storeId = 1;
64  $currencyCode = 'usd';
65 
66  $productMock = $this->getMockBuilder(Product::class)
67  ->disableOriginalConstructor()
68  ->getMock();
69  $price = $this->getMockBuilder(FinalPrice::class)
70  ->disableOriginalConstructor()
71  ->getMock();
72  $productRender = $this->getMockBuilder(ProductRenderInterface::class)
73  ->disableOriginalConstructor()
74  ->getMock();
75  $amount = $this->getMockBuilder(AmountInterface::class)
76  ->disableOriginalConstructor()
77  ->getMock();
78  $minAmount = $this->getMockBuilder(AmountInterface::class)
79  ->disableOriginalConstructor()
80  ->getMock();
81  $priceInfo = $this->getMockBuilder(PriceInfoInterface::class)
82  ->setMethods(
83  [
84  'getPrice',
85  'setMaxPrice',
86  'setMaxRegularPrice',
87  'setMinimalPrice',
88  'setMinimalRegularPrice'
89  ]
90  )
91  ->getMockForAbstractClass();
92 
93  $productMock->expects($this->once())
94  ->method('getTypeId')
95  ->willReturn('bundle');
96  $productRender->expects($this->exactly(2))
97  ->method('getPriceInfo')
98  ->willReturn($priceInfo);
99  $priceInfo->expects($this->once())
100  ->method('setMaxPrice')
101  ->with($amountValue);
102  $priceInfo->expects($this->once())
103  ->method('setMaxRegularPrice')
104  ->with($amountValue);
105  $priceInfo->expects($this->once())
106  ->method('setMinimalPrice')
107  ->with($minAmountValue);
108  $priceInfo->expects($this->once())
109  ->method('setMinimalRegularPrice')
110  ->with($minAmountValue);
111  $productMock->expects($this->exactly(4))
112  ->method('getPriceInfo')
113  ->willReturn($priceInfo);
114  $productMock->expects($this->any())
115  ->method('getPriceInfo')
116  ->willReturn($priceInfo);
117  $priceInfo->expects($this->exactly(4))
118  ->method('getPrice')
119  ->willReturn($price);
120  $price->expects($this->exactly(2))
121  ->method('getMaximalPrice')
122  ->willReturn($amount);
123  $price->expects($this->exactly(2))
124  ->method('getMinimalPrice')
125  ->willReturn($minAmount);
126  $amount->expects($this->exactly(2))
127  ->method('getValue')
128  ->willReturn($amountValue);
129  $minAmount->expects($this->exactly(2))
130  ->method('getValue')
131  ->willReturn($minAmountValue);
132 
133  $productRender->expects($this->once())
134  ->method('getStoreId')
135  ->willReturn(1);
136  $productRender->expects($this->once())
137  ->method('getCurrencyCode')
138  ->willReturn($currencyCode);
139 
140  $this->formattedPriceInfoBuilder->expects($this->once())
141  ->method('build')
142  ->with($priceInfo, $storeId, $currencyCode);
143  $productRender->expects($this->once())
144  ->method('setPriceInfo')
145  ->with($priceInfo);
146 
147  $this->model->collect($productMock, $productRender);
148  }
149 }
$price
$amount
Definition: order.php:14