Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RegularPriceTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Catalog\Pricing\Price\RegularPrice;
10 
14 class RegularPriceTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $regularPrice;
20 
24  protected $priceInfoMock;
25 
29  protected $saleableItemMock;
30 
34  protected $calculatorMock;
35 
39  protected $priceCurrencyMock;
40 
44  protected function setUp()
45  {
46  $qty = 1;
47  $this->saleableItemMock = $this->createMock(\Magento\Catalog\Model\Product::class);
48  $this->priceInfoMock = $this->createMock(\Magento\Framework\Pricing\PriceInfo\Base::class);
49  $this->calculatorMock = $this->createMock(\Magento\Framework\Pricing\Adjustment\Calculator::class);
50 
51  $this->saleableItemMock->expects($this->once())
52  ->method('getPriceInfo')
53  ->will($this->returnValue($this->priceInfoMock));
54 
55  $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
56 
57  $this->regularPrice = new RegularPrice(
58  $this->saleableItemMock,
59  $qty,
60  $this->calculatorMock,
61  $this->priceCurrencyMock
62  );
63  }
64 
71  public function testGetValue($price)
72  {
73  $convertedPrice = 85;
74  $this->saleableItemMock->expects($this->once())
75  ->method('getPrice')
76  ->will($this->returnValue($price));
77  $this->priceCurrencyMock->expects($this->any())
78  ->method('convertAndRound')
79  ->with($price)
80  ->will($this->returnValue($convertedPrice));
81  $this->assertEquals($convertedPrice, $this->regularPrice->getValue());
82  //The second call will use cached value
83  $this->assertEquals($convertedPrice, $this->regularPrice->getValue());
84  }
85 
91  public function testGetValueDataProvider()
92  {
93  return [
94  'With price' => [100.00],
95  'Without price' => [false]
96  ];
97  }
98 
102  public function testGetAmount()
103  {
104  $priceValue = 77;
105  $convertedPrice = 56.32;
106  $amountValue = 88;
107 
108  $this->saleableItemMock->expects($this->once())
109  ->method('getPrice')
110  ->will($this->returnValue($priceValue));
111  $this->priceCurrencyMock->expects($this->any())
112  ->method('convertAndRound')
113  ->with($priceValue)
114  ->will($this->returnValue($convertedPrice));
115  $this->calculatorMock->expects($this->once())
116  ->method('getAmount')
117  ->with($this->equalTo($convertedPrice))
118  ->will($this->returnValue($amountValue));
119  $this->assertEquals($amountValue, $this->regularPrice->getAmount());
120  }
121 
125  public function testGetPriceCode()
126  {
127  $this->assertEquals(RegularPrice::PRICE_CODE, $this->regularPrice->getPriceCode());
128  }
129 }
$price