Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PricesTest.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
11 use PHPUnit\Framework\TestCase;
12 
13 class PricesTest extends TestCase
14 {
18  private $localeFormatMock;
19 
23  private $model;
24 
25  protected function setUp()
26  {
27  $this->localeFormatMock = $this->createMock(\Magento\Framework\Locale\Format::class);
28  $this->model = new \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Variations\Prices(
29  $this->localeFormatMock
30  );
31  }
32 
33  public function testGetFormattedPrices()
34  {
35  $expected = [
36  'oldPrice' => [
37  'amount' => 500
38  ],
39  'basePrice' => [
40  'amount' => 1000
41  ],
42  'finalPrice' => [
43  'amount' => 500
44  ]
45  ];
46  $priceInfoMock = $this->createMock(\Magento\Framework\Pricing\PriceInfo\Base::class);
47  $priceMock = $this->createMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
48  $priceInfoMock->expects($this->atLeastOnce())->method('getPrice')->willReturn($priceMock);
49 
50  $amountMock = $this->createMock(\Magento\Framework\Pricing\Amount\AmountInterface::class);
51  $amountMock->expects($this->atLeastOnce())->method('getValue')->willReturn(500);
52  $amountMock->expects($this->atLeastOnce())->method('getBaseAmount')->willReturn(1000);
53  $priceMock->expects($this->atLeastOnce())->method('getAmount')->willReturn($amountMock);
54 
55  $this->localeFormatMock->expects($this->atLeastOnce())
56  ->method('getNumber')
57  ->withConsecutive([500], [1000], [500])
58  ->will($this->onConsecutiveCalls(500, 1000, 500));
59 
60  $this->assertEquals($expected, $this->model->getFormattedPrices($priceInfoMock));
61  }
62 }