-
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
Changes from all commits
f649582
a1575f7
3a92f3e
c717b34
995cb2a
b0c2133
1aa93e0
33914c1
0f32c4d
72facef
e1b094b
9625436
f34f5c8
2ec38bc
0669115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<?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\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 ConfiguredPriceTest extends TestCase | ||
{ | ||
/** | ||
* @var float | ||
*/ | ||
private $basePriceValue = 100.00; | ||
|
||
/** | ||
* @var ItemInterface|MockObject | ||
*/ | ||
private $itemMock; | ||
|
||
/** | ||
* @var Product|MockObject | ||
*/ | ||
private $productMock; | ||
|
||
/** | ||
* @var Calculator|MockObject | ||
*/ | ||
private $calculatorMock; | ||
|
||
/** | ||
* @var Base|MockObject | ||
*/ | ||
private $priceInfoMock; | ||
|
||
/** | ||
* @var ConfiguredPrice | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var PriceCurrencyInterface|MockObject | ||
*/ | ||
private $priceCurrencyMock; | ||
|
||
/** | ||
* @var Json|MockObject | ||
*/ | ||
private $jsonSerializerMock; | ||
|
||
/** | ||
* @var ConfiguredPriceSelection|MockObject | ||
*/ | ||
private $configuredPriceSelectionMock; | ||
|
||
/** | ||
* @var AmountInterface|MockObject | ||
*/ | ||
private $amountInterfaceMock; | ||
|
||
/** | ||
* @var DiscountCalculator|MockObject | ||
*/ | ||
private $discountCalculatorMock; | ||
|
||
/** | ||
* Initialize base dependencies | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$basePrice = $this->getMockForAbstractClass(PriceInterface::class); | ||
$basePrice->expects($this->any())->method('getValue')->willReturn($this->basePriceValue); | ||
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. Basically the 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. Ok. But in setUp I dont have assertions |
||
|
||
$this->priceInfoMock = $this->createMock(Base::class); | ||
$this->priceInfoMock->expects($this->any())->method('getPrice')->willReturn($basePrice); | ||
$this->productMock = $this->getMockBuilder(Product::class) | ||
->setMethods(['getPriceInfo', 'getOptionById', 'getResource', 'getId']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->productMock->expects($this->once())->method('getPriceInfo')->willReturn($this->priceInfoMock); | ||
$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.00); | ||
$this->calculatorMock = $this->getMockBuilder(Calculator::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->calculatorMock->expects($this->any())->method('calculateBundleAmount') | ||
->willReturn($this->amountInterfaceMock); | ||
$this->discountCalculatorMock = $this->getMockBuilder(DiscountCalculator::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->discountCalculatorMock->expects($this->any())->method('calculateDiscount') | ||
->willReturn(-5.00); | ||
$this->model = new ConfiguredPrice( | ||
$this->productMock, | ||
1, | ||
$this->calculatorMock, | ||
$this->priceCurrencyMock, | ||
null, | ||
$this->jsonSerializerMock, | ||
$this->configuredPriceSelectionMock, | ||
$this->discountCalculatorMock, | ||
); | ||
} | ||
|
||
/** | ||
* Test of value getter when item presented | ||
*/ | ||
public function testGetValueMethod(): void | ||
{ | ||
$this->productMock->expects($this->any())->method('getId')->willReturn(123); | ||
$this->itemMock = $this->getMockBuilder(ItemInterface::class) | ||
->getMock(); | ||
$this->itemMock->expects($this->any())->method('getProduct')->willReturn($this->productMock); | ||
$this->model->setItem($this->itemMock); | ||
$valueFromMock = $this->model->getValue(); | ||
$this->assertEquals(95.00, $valueFromMock); | ||
} | ||
|
||
/** | ||
* Test of value getter if no product item | ||
*/ | ||
public function testGetValueMethodNoItem(): void | ||
{ | ||
$this->productMock = $this->getMockBuilder(Product::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->itemMock = $this->getMockBuilder(ItemInterface::class) | ||
->getMock(); | ||
$this->itemMock->expects($this->any())->method('getProduct')->willReturn($this->productMock); | ||
$this->productMock->expects($this->any())->method('getId')->willReturn(false); | ||
$this->model->setItem($this->itemMock); | ||
$valueFromMock = $this->model->getValue(); | ||
$this->assertEquals(100.00, $valueFromMock); | ||
} | ||
|
||
/** | ||
* Stub data for calculation amount of bundle | ||
* @return \Magento\Framework\DataObject[] | ||
*/ | ||
private function prepareAndReturnSelectionPriceDataStub(): array | ||
{ | ||
$first = new DataObject(); | ||
$first->setValue(2); | ||
$first->setQuantity(1); | ||
$second = new DataObject(); | ||
$second->setValue(3); | ||
$second->setQuantity(1); | ||
return [ | ||
$first, | ||
$second | ||
]; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.