Skip to content

Commit 2ec38bc

Browse files
committed
#33334:Inheriting from a class that doesn't exist
- Adjusted code style for configuredPriceSelection propery in the target code - Added mock suffice to last property in unit test - Added decimals after point in unit test - Transferred setting up some mocks to the specific test case
1 parent f34f5c8 commit 2ec38bc

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice
4848
* @var ConfiguredPriceSelection
4949
*/
5050
private $configuredPriceSelection;
51+
5152
/**
5253
* @var DiscountCalculator
5354
*/

app/code/Magento/Bundle/Test/Unit/Pricing/Price/ConfiguredPriceTest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ConfiguredPriceTest extends TestCase
3030
/**
3131
* @var float
3232
*/
33-
private $basePriceValue = 100.;
33+
private $basePriceValue = 100.00;
3434

3535
/**
3636
* @var ItemInterface|MockObject
@@ -43,9 +43,9 @@ class ConfiguredPriceTest extends TestCase
4343
private $productMock;
4444

4545
/**
46-
* @var MockObject
46+
* @var Calculator|MockObject
4747
*/
48-
private $calculator;
48+
private $calculatorMock;
4949

5050
/**
5151
* @var Base|MockObject
@@ -97,12 +97,6 @@ protected function setUp(): void
9797
->disableOriginalConstructor()
9898
->getMock();
9999
$this->productMock->expects($this->once())->method('getPriceInfo')->willReturn($this->priceInfoMock);
100-
$this->productMock->expects($this->any())->method('getId')->willReturn(123);
101-
102-
$this->itemMock = $this->getMockBuilder(ItemInterface::class)
103-
->getMock();
104-
$this->itemMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
105-
106100
$this->priceCurrencyMock = $this->getMockForAbstractClass(PriceCurrencyInterface::class);
107101

108102
$this->jsonSerializerMock = $this->getMockBuilder(Json::class)
@@ -115,37 +109,41 @@ protected function setUp(): void
115109
->willReturn($this->prepareAndReturnSelectionPriceDataStub());
116110
$this->amountInterfaceMock = $this->getMockBuilder(AmountInterface::class)->getMock();
117111
$this->amountInterfaceMock->expects($this->any())->method('getBaseAmount')
118-
->willReturn(100.0);
119-
$this->calculator = $this->getMockBuilder(Calculator::class)
112+
->willReturn(100.00);
113+
$this->calculatorMock = $this->getMockBuilder(Calculator::class)
120114
->disableOriginalConstructor()
121115
->getMock();
122-
$this->calculator->expects($this->any())->method('calculateBundleAmount')
116+
$this->calculatorMock->expects($this->any())->method('calculateBundleAmount')
123117
->willReturn($this->amountInterfaceMock);
124118
$this->discountCalculatorMock = $this->getMockBuilder(DiscountCalculator::class)
125119
->disableOriginalConstructor()
126120
->getMock();
127121
$this->discountCalculatorMock->expects($this->any())->method('calculateDiscount')
128-
->willReturn(-5.0);
122+
->willReturn(-5.00);
129123
$this->model = new ConfiguredPrice(
130124
$this->productMock,
131125
1,
132-
$this->calculator,
126+
$this->calculatorMock,
133127
$this->priceCurrencyMock,
134128
null,
135129
$this->jsonSerializerMock,
136130
$this->configuredPriceSelectionMock,
137131
$this->discountCalculatorMock,
138132
);
139-
$this->model->setItem($this->itemMock);
140133
}
141134

142135
/**
143136
* Test of value getter when item presented
144137
*/
145138
public function testGetValueMethod(): void
146139
{
140+
$this->productMock->expects($this->any())->method('getId')->willReturn(123);
141+
$this->itemMock = $this->getMockBuilder(ItemInterface::class)
142+
->getMock();
143+
$this->itemMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
144+
$this->model->setItem($this->itemMock);
147145
$valueFromMock = $this->model->getValue();
148-
$this->assertEquals(95., $valueFromMock);
146+
$this->assertEquals(95.00, $valueFromMock);
149147
}
150148

151149
/**
@@ -162,7 +160,7 @@ public function testGetValueMethodNoItem(): void
162160
$this->productMock->expects($this->any())->method('getId')->willReturn(false);
163161
$this->model->setItem($this->itemMock);
164162
$valueFromMock = $this->model->getValue();
165-
$this->assertEquals(100., $valueFromMock);
163+
$this->assertEquals(100.00, $valueFromMock);
166164
}
167165

168166
/**

0 commit comments

Comments
 (0)