BundleOptionRegularPriceTest.php 4.0 KB

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