-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Inheriting from a class that doesn't exist#33334 #33449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 15 commits into
magento:2.4-develop
from
monteshot:Inheriting_from_a_class_that_doesn't_exist#33334
Sep 23, 2021
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f649582
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot a1575f7
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot 3a92f3e
Removed unnecessary nesting in if statements according to the interface
monteshot c717b34
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot 995cb2a
Merge remote-tracking branch 'origin/Inheriting_from_a_class_that_doe…
monteshot b0c2133
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot 1aa93e0
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot 33914c1
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot 0f32c4d
magento#33334:Inheriting from a class that doesn't exist
monteshot 72facef
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot e1b094b
Merge remote-tracking branch 'origin/Inheriting_from_a_class_that_doe…
monteshot 9625436
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot f34f5c8
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot 2ec38bc
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot 0669115
magento/magento2#33334:Inheriting from a class that doesn't exist
monteshot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -48,6 +48,10 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice | |||||||||||
* @var ConfiguredPriceSelection | ||||||||||||
*/ | ||||||||||||
private $configuredPriceSelection; | ||||||||||||
/** | ||||||||||||
* @var \Magento\Bundle\Pricing\Price\DiscountCalculator | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please preserve an empty row and do not use FQPN. Please import the class name.
Suggested change
|
||||||||||||
*/ | ||||||||||||
private $discountCalculator; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* @param Product $saleableItem | ||||||||||||
|
@@ -63,6 +67,7 @@ public function __construct( | |||||||||||
$quantity, | ||||||||||||
BundleCalculatorInterface $calculator, | ||||||||||||
PriceCurrencyInterface $priceCurrency, | ||||||||||||
DiscountCalculator $discountCalculator, | ||||||||||||
ItemInterface $item = null, | ||||||||||||
JsonSerializer $serializer = null, | ||||||||||||
ConfiguredPriceSelection $configuredPriceSelection = null | ||||||||||||
|
@@ -73,6 +78,7 @@ public function __construct( | |||||||||||
$this->configuredPriceSelection = $configuredPriceSelection | ||||||||||||
?: \Magento\Framework\App\ObjectManager::getInstance() | ||||||||||||
->get(ConfiguredPriceSelection::class); | ||||||||||||
$this->discountCalculator = $discountCalculator; | ||||||||||||
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
@@ -146,10 +152,9 @@ public function getValue() | |||||||||||
{ | ||||||||||||
if ($this->item) { | ||||||||||||
$configuredOptionsAmount = $this->getConfiguredAmount()->getBaseAmount(); | ||||||||||||
return parent::getValue() + | ||||||||||||
$this->priceInfo | ||||||||||||
->getPrice(BundleDiscountPrice::PRICE_CODE) | ||||||||||||
->calculateDiscount($configuredOptionsAmount); | ||||||||||||
if (!empty($this->item->getProduct())) { | ||||||||||||
monteshot marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
return parent::getValue() + $this->discountCalculator->calculateDiscount($this->item->getProduct(), $configuredOptionsAmount); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
return parent::getValue(); | ||||||||||||
} | ||||||||||||
|
156 changes: 156 additions & 0 deletions
156
app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundlePriceTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Bundle\Test\Unit\Pricing\Price; | ||
|
||
use Magento\Bundle\Pricing\Price\DiscountCalculator; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface; | ||
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface; | ||
use Magento\Catalog\Model\Product\Option; | ||
use Magento\Catalog\Model\Product\Option\Type\DefaultType; | ||
use Magento\Bundle\Pricing\Price\ConfiguredPrice; | ||
use Magento\Bundle\Pricing\Adjustment\Calculator; | ||
use Magento\Catalog\Pricing\Price\ConfiguredPriceSelection; | ||
use Magento\Framework\DataObject; | ||
use Magento\Framework\Pricing\Amount\AmountInterface; | ||
use Magento\Framework\Pricing\Price\PriceInterface; | ||
use Magento\Framework\Pricing\PriceCurrencyInterface; | ||
use Magento\Framework\Pricing\PriceInfo\Base; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test for \Magento\Bundle\Pricing\Price\ConfiguredPrice | ||
*/ | ||
class BundlePriceTest extends TestCase | ||
{ | ||
/** | ||
* @var float | ||
*/ | ||
protected $basePriceValue = 100.; | ||
|
||
/** | ||
* @var MockObject | ||
*/ | ||
protected $item; | ||
|
||
/** | ||
* @var MockObject | ||
*/ | ||
protected $product; | ||
|
||
/** | ||
* @var MockObject | ||
*/ | ||
protected $calculator; | ||
|
||
/** | ||
* @var MockObject | ||
*/ | ||
protected $priceInfo; | ||
|
||
/** | ||
* @var ConfiguredPrice | ||
*/ | ||
protected $model; | ||
|
||
/** | ||
* @var PriceCurrencyInterface|MockObject | ||
*/ | ||
protected $priceCurrencyMock; | ||
/** | ||
* @var Json|MockObject | ||
*/ | ||
private $jsonSerializerMock; | ||
/** | ||
* @var ConfiguredPriceSelection|MockObject | ||
*/ | ||
private $configuredPriceSelectionMock; | ||
/** | ||
* @var array | ||
*/ | ||
private $selectionPriceDataSampleData; | ||
/** | ||
* @var AmountInterface|MockObject | ||
*/ | ||
private $amountInterfaceMock; | ||
/** | ||
* @var DiscountCalculator|MockObject | ||
*/ | ||
private $discountCalculator; | ||
|
||
/** | ||
* Initialize base dependencies | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$basePrice = $this->getMockForAbstractClass(PriceInterface::class); | ||
$basePrice->expects($this->any())->method('getValue')->willReturn($this->basePriceValue); | ||
|
||
$this->priceInfo = $this->createMock(Base::class); | ||
$this->priceInfo->expects($this->any())->method('getPrice')->willReturn($basePrice); | ||
$this->product = $this->getMockBuilder(Product::class) | ||
->setMethods(['getPriceInfo', 'getOptionById', 'getResource']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->product->expects($this->once())->method('getPriceInfo')->willReturn($this->priceInfo); | ||
|
||
$this->item = $this->getMockBuilder(ItemInterface::class) | ||
->getMock(); | ||
$this->item->expects($this->any())->method('getProduct')->willReturn($this->product); | ||
|
||
$this->priceCurrencyMock = $this->getMockForAbstractClass(PriceCurrencyInterface::class); | ||
|
||
$this->jsonSerializerMock = $this->getMockBuilder(Json::class) | ||
->getMock(); | ||
$this->configuredPriceSelectionMock = $this->getMockBuilder(ConfiguredPriceSelection::class) | ||
->setMethods(['getSelectionPriceList']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->configuredPriceSelectionMock->expects($this->any())->method('getSelectionPriceList') | ||
->willReturn($this->prepareAndReturnSelectionPriceDataStub()); | ||
$this->amountInterfaceMock = $this->getMockBuilder(AmountInterface::class)->getMock(); | ||
$this->amountInterfaceMock->expects($this->any())->method('getBaseAmount') | ||
->willReturn(100.0); | ||
$this->calculator = $this->getMockBuilder(Calculator::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->calculator->expects($this->any())->method('calculateBundleAmount') | ||
->willReturn($this->amountInterfaceMock); | ||
$this->discountCalculator = $this->getMockBuilder(DiscountCalculator::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->discountCalculator->expects($this->any())->method('calculateDiscount') | ||
->willReturn(-5.0); | ||
$this->model = new ConfiguredPrice($this->product, 1, $this->calculator, $this->priceCurrencyMock, $this->discountCalculator,null, $this->jsonSerializerMock, $this->configuredPriceSelectionMock); | ||
$this->model->setItem($this->item); | ||
} | ||
|
||
private function prepareAndReturnSelectionPriceDataStub() | ||
{ | ||
$first = new DataObject(); | ||
$first->setValue(2); | ||
$first->setQuantity(1); | ||
$second = new DataObject(); | ||
$second->setValue(3); | ||
$second->setQuantity(1); | ||
return [ | ||
$first, | ||
$second | ||
]; | ||
} | ||
/** | ||
* Test of value getter | ||
*/ | ||
public function testGetValueMethod() | ||
{ | ||
$valueFromMock = $this->model->getValue(); | ||
$this->assertEquals(95., $valueFromMock); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.