123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Bundle\Test\Unit\Pricing\Price;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
- use Magento\Framework\Pricing\Amount\AmountInterface;
- use Magento\Catalog\Model\Product;
- use Magento\Bundle\Pricing\Price\BundleOptions;
- use Magento\Bundle\Pricing\Adjustment\Calculator;
- use \Magento\Bundle\Model\Selection;
- class BundleOptionPriceTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Bundle\Pricing\Price\BundleOptionPrice
- */
- private $bundleOptionPrice;
- /**
- * @var ObjectManagerHelper
- */
- private $objectManagerHelper;
- /**
- * @var \Magento\Framework\Pricing\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $saleableItemMock;
- /**
- * @var \Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $bundleCalculatorMock;
- /**
- * @var BundleOptions|\PHPUnit_Framework_MockObject_MockObject
- */
- private $bundleOptionsMock;
- /**
- * @inheritdoc
- */
- protected function setUp()
- {
- $this->bundleOptionsMock = $this->createMock(BundleOptions::class);
- $this->saleableItemMock = $this->createMock(Product::class);
- $this->bundleCalculatorMock = $this->createMock(Calculator::class);
- $this->objectManagerHelper = new ObjectManagerHelper($this);
- $this->bundleOptionPrice = $this->objectManagerHelper->getObject(
- \Magento\Bundle\Pricing\Price\BundleOptionPrice::class,
- [
- 'saleableItem' => $this->saleableItemMock,
- 'quantity' => 1.,
- 'calculator' => $this->bundleCalculatorMock,
- 'bundleOptions' => $this->bundleOptionsMock,
- ]
- );
- }
- /**
- * Test method \Magento\Bundle\Pricing\Price\BundleOptionPrice::getOptions
- *
- * @return void
- */
- public function testGetOptions()
- {
- $collection = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class);
- $this->bundleOptionsMock->expects($this->any())
- ->method('getOptions')
- ->will($this->returnValue($collection));
- $this->assertEquals($collection, $this->bundleOptionPrice->getOptions());
- }
- /**
- * Test method \Magento\Bundle\Pricing\Price\BundleOptionPrice::getOptionSelectionAmount
- *
- * @return void
- */
- public function testGetOptionSelectionAmount()
- {
- $selectionAmount = $this->createMock(AmountInterface::class);
- $product = $this->createMock(Product::class);
- $selection = $this->createMock(Selection::class);
- $this->bundleOptionsMock->expects($this->any())
- ->method('getOptionSelectionAmount')
- ->will($this->returnValue($selectionAmount))
- ->with($product, $selection, false);
- $this->assertEquals($selectionAmount, $this->bundleOptionPrice->getOptionSelectionAmount($selection));
- }
- /**
- * Test method \Magento\Bundle\Pricing\Price\BundleOptionPrice::getAmount
- *
- * @return void
- */
- public function testGetAmount()
- {
- $amountMock = $this->createMock(AmountInterface::class);
- $this->bundleCalculatorMock->expects($this->once())
- ->method('getOptionsAmount')
- ->with($this->equalTo($this->saleableItemMock))
- ->will($this->returnValue($amountMock));
- $this->assertSame($amountMock, $this->bundleOptionPrice->getAmount());
- }
- /**
- * Test method \Magento\Bundle\Pricing\Price\BundleOptionPrice::getValue
- *
- * @return void
- */
- public function testGetValue()
- {
- $value = 1;
- $this->bundleOptionsMock->expects($this->any())->method('calculateOptions')->will($this->returnValue($value));
- $this->assertEquals($value, $this->bundleOptionPrice->getValue());
- }
- }
|