Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LinkPriceTest.php
Go to the documentation of this file.
1 <?php
8 
12 class LinkPriceTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $linkPrice;
18 
22  protected $amountMock;
23 
27  protected $saleableItemMock;
28 
32  protected $calculatorMock;
33 
37  protected $linkMock;
38 
42  protected $priceCurrencyMock;
43 
47  protected function setUp()
48  {
49  $this->saleableItemMock = $this->createMock(\Magento\Catalog\Model\Product::class);
50  $this->amountMock = $this->createMock(\Magento\Framework\Pricing\Amount\Base::class);
51  $this->calculatorMock = $this->createMock(\Magento\Framework\Pricing\Adjustment\Calculator::class);
52  $this->linkMock = $this->createPartialMock(
53  \Magento\Downloadable\Model\Link::class,
54  ['getPrice', 'getProduct', '__wakeup']
55  );
56 
57  $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
58 
59  $this->linkPrice = new \Magento\Downloadable\Pricing\Price\LinkPrice(
60  $this->saleableItemMock,
61  1,
62  $this->calculatorMock,
63  $this->priceCurrencyMock
64  );
65  }
66 
67  public function testGetLinkAmount()
68  {
69  $amount = 100;
70  $convertedAmount = 50;
71 
72  $this->linkMock->expects($this->once())
73  ->method('getPrice')
74  ->will($this->returnValue($amount));
75  $this->linkMock->expects($this->once())
76  ->method('getProduct')
77  ->will($this->returnValue($this->saleableItemMock));
78  $this->priceCurrencyMock->expects($this->once())
79  ->method('convertAndRound')
80  ->with($amount)
81  ->will($this->returnValue($convertedAmount));
82  $this->calculatorMock->expects($this->once())
83  ->method('getAmount')
84  ->with($convertedAmount, $this->equalTo($this->saleableItemMock))
85  ->will($this->returnValue($convertedAmount));
86 
87  $result = $this->linkPrice->getLinkAmount($this->linkMock);
88  $this->assertEquals($convertedAmount, $result);
89  }
90 }
$amount
Definition: order.php:14