Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BundleOptionPriceTest.php
Go to the documentation of this file.
1 <?php
8 
14 use \Magento\Bundle\Model\Selection;
15 
16 class BundleOptionPriceTest extends \PHPUnit\Framework\TestCase
17 {
21  private $bundleOptionPrice;
22 
26  private $objectManagerHelper;
27 
31  private $saleableItemMock;
32 
36  private $bundleCalculatorMock;
37 
41  private $bundleOptionsMock;
42 
46  protected function setUp()
47  {
48  $this->bundleOptionsMock = $this->createMock(BundleOptions::class);
49  $this->saleableItemMock = $this->createMock(Product::class);
50  $this->bundleCalculatorMock = $this->createMock(Calculator::class);
51 
52  $this->objectManagerHelper = new ObjectManagerHelper($this);
53  $this->bundleOptionPrice = $this->objectManagerHelper->getObject(
54  \Magento\Bundle\Pricing\Price\BundleOptionPrice::class,
55  [
56  'saleableItem' => $this->saleableItemMock,
57  'quantity' => 1.,
58  'calculator' => $this->bundleCalculatorMock,
59  'bundleOptions' => $this->bundleOptionsMock,
60  ]
61  );
62  }
63 
69  public function testGetOptions()
70  {
71  $collection = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class);
72  $this->bundleOptionsMock->expects($this->any())
73  ->method('getOptions')
74  ->will($this->returnValue($collection));
75  $this->assertEquals($collection, $this->bundleOptionPrice->getOptions());
76  }
77 
83  public function testGetOptionSelectionAmount()
84  {
85  $selectionAmount = $this->createMock(AmountInterface::class);
86  $product = $this->createMock(Product::class);
87  $selection = $this->createMock(Selection::class);
88  $this->bundleOptionsMock->expects($this->any())
89  ->method('getOptionSelectionAmount')
90  ->will($this->returnValue($selectionAmount))
91  ->with($product, $selection, false);
92  $this->assertEquals($selectionAmount, $this->bundleOptionPrice->getOptionSelectionAmount($selection));
93  }
94 
100  public function testGetAmount()
101  {
102  $amountMock = $this->createMock(AmountInterface::class);
103  $this->bundleCalculatorMock->expects($this->once())
104  ->method('getOptionsAmount')
105  ->with($this->equalTo($this->saleableItemMock))
106  ->will($this->returnValue($amountMock));
107  $this->assertSame($amountMock, $this->bundleOptionPrice->getAmount());
108  }
109 
115  public function testGetValue()
116  {
117  $value = 1;
118  $this->bundleOptionsMock->expects($this->any())->method('calculateOptions')->will($this->returnValue($value));
119  $this->assertEquals($value, $this->bundleOptionPrice->getValue());
120  }
121 }
$value
Definition: gender.phtml:16