BundleOptionPriceTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Test\Unit\Pricing\Price;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. use Magento\Framework\Pricing\Amount\AmountInterface;
  9. use Magento\Catalog\Model\Product;
  10. use Magento\Bundle\Pricing\Price\BundleOptions;
  11. use Magento\Bundle\Pricing\Adjustment\Calculator;
  12. use \Magento\Bundle\Model\Selection;
  13. class BundleOptionPriceTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var \Magento\Bundle\Pricing\Price\BundleOptionPrice
  17. */
  18. private $bundleOptionPrice;
  19. /**
  20. * @var ObjectManagerHelper
  21. */
  22. private $objectManagerHelper;
  23. /**
  24. * @var \Magento\Framework\Pricing\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
  25. */
  26. private $saleableItemMock;
  27. /**
  28. * @var \Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface|\PHPUnit_Framework_MockObject_MockObject
  29. */
  30. private $bundleCalculatorMock;
  31. /**
  32. * @var BundleOptions|\PHPUnit_Framework_MockObject_MockObject
  33. */
  34. private $bundleOptionsMock;
  35. /**
  36. * @inheritdoc
  37. */
  38. protected function setUp()
  39. {
  40. $this->bundleOptionsMock = $this->createMock(BundleOptions::class);
  41. $this->saleableItemMock = $this->createMock(Product::class);
  42. $this->bundleCalculatorMock = $this->createMock(Calculator::class);
  43. $this->objectManagerHelper = new ObjectManagerHelper($this);
  44. $this->bundleOptionPrice = $this->objectManagerHelper->getObject(
  45. \Magento\Bundle\Pricing\Price\BundleOptionPrice::class,
  46. [
  47. 'saleableItem' => $this->saleableItemMock,
  48. 'quantity' => 1.,
  49. 'calculator' => $this->bundleCalculatorMock,
  50. 'bundleOptions' => $this->bundleOptionsMock,
  51. ]
  52. );
  53. }
  54. /**
  55. * Test method \Magento\Bundle\Pricing\Price\BundleOptionPrice::getOptions
  56. *
  57. * @return void
  58. */
  59. public function testGetOptions()
  60. {
  61. $collection = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class);
  62. $this->bundleOptionsMock->expects($this->any())
  63. ->method('getOptions')
  64. ->will($this->returnValue($collection));
  65. $this->assertEquals($collection, $this->bundleOptionPrice->getOptions());
  66. }
  67. /**
  68. * Test method \Magento\Bundle\Pricing\Price\BundleOptionPrice::getOptionSelectionAmount
  69. *
  70. * @return void
  71. */
  72. public function testGetOptionSelectionAmount()
  73. {
  74. $selectionAmount = $this->createMock(AmountInterface::class);
  75. $product = $this->createMock(Product::class);
  76. $selection = $this->createMock(Selection::class);
  77. $this->bundleOptionsMock->expects($this->any())
  78. ->method('getOptionSelectionAmount')
  79. ->will($this->returnValue($selectionAmount))
  80. ->with($product, $selection, false);
  81. $this->assertEquals($selectionAmount, $this->bundleOptionPrice->getOptionSelectionAmount($selection));
  82. }
  83. /**
  84. * Test method \Magento\Bundle\Pricing\Price\BundleOptionPrice::getAmount
  85. *
  86. * @return void
  87. */
  88. public function testGetAmount()
  89. {
  90. $amountMock = $this->createMock(AmountInterface::class);
  91. $this->bundleCalculatorMock->expects($this->once())
  92. ->method('getOptionsAmount')
  93. ->with($this->equalTo($this->saleableItemMock))
  94. ->will($this->returnValue($amountMock));
  95. $this->assertSame($amountMock, $this->bundleOptionPrice->getAmount());
  96. }
  97. /**
  98. * Test method \Magento\Bundle\Pricing\Price\BundleOptionPrice::getValue
  99. *
  100. * @return void
  101. */
  102. public function testGetValue()
  103. {
  104. $value = 1;
  105. $this->bundleOptionsMock->expects($this->any())->method('calculateOptions')->will($this->returnValue($value));
  106. $this->assertEquals($value, $this->bundleOptionPrice->getValue());
  107. }
  108. }