Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MinimalTierPriceCalculatorTest.php
Go to the documentation of this file.
1 <?php
8 
16 
17 class MinimalTierPriceCalculatorTest extends \PHPUnit\Framework\TestCase
18 {
22  private $objectManager;
23 
27  private $object;
28 
32  private $saleable;
33 
37  private $priceInfo;
38 
42  private $price;
43 
47  private $calculator;
48 
49  public function setUp()
50  {
51  $this->price = $this->createMock(TierPrice::class);
52  $this->priceInfo = $this->getMockForAbstractClass(PriceInfoInterface::class);
53  $this->saleable = $this->getMockForAbstractClass(SaleableInterface::class);
54 
55  $this->objectManager = new ObjectManager($this);
56 
57  $this->calculator = $this->getMockForAbstractClass(CalculatorInterface::class);
58  $this->object = $this->objectManager->getObject(
59  MinimalTierPriceCalculator::class,
60  ['calculator' => $this->calculator]
61  );
62  }
63 
67  private function getValueTierPricesExistShouldReturnMinTierPrice()
68  {
69  $minPrice = 5;
70  $notMinPrice = 10;
71 
72  $minAmount = $this->getMockForAbstractClass(AmountInterface::class);
73  $minAmount->expects($this->once())->method('getValue')->willReturn($minPrice);
74 
75  $notMinAmount = $this->getMockForAbstractClass(AmountInterface::class);
76  $notMinAmount->expects($this->once())->method('getValue')->willReturn($notMinPrice);
77 
78  $tierPriceList = [
79  [
80  'price' => $minAmount
81  ],
82  [
83  'price' => $notMinAmount
84  ]
85  ];
86 
87  $this->price->expects($this->once())->method('getTierPriceList')->willReturn($tierPriceList);
88 
89  $this->priceInfo->expects($this->once())->method('getPrice')->with(TierPrice::PRICE_CODE)
90  ->willReturn($this->price);
91 
92  $this->saleable->expects($this->once())->method('getPriceInfo')->willReturn($this->priceInfo);
93  return $minPrice;
94  }
95 
97  {
98  $minPrice = $this->getValueTierPricesExistShouldReturnMinTierPrice();
99  $this->assertEquals($minPrice, $this->object->getValue($this->saleable));
100  }
101 
103  {
104  $minPrice = $this->getValueTierPricesExistShouldReturnMinTierPrice();
105 
106  $amount = $this->getMockForAbstractClass(AmountInterface::class);
107 
108  $this->calculator->expects($this->once())
109  ->method('getAmount')
110  ->with($minPrice, $this->saleable)
111  ->willReturn($amount);
112 
113  $this->assertSame($amount, $this->object->getAmount($this->saleable));
114  }
115 }
$amount
Definition: order.php:14