Skip to content

Commit f34f5c8

Browse files
committed
#33334:Inheriting from a class that doesn't exist
- Adjusted code style for the unit test - Replaced FQPN using import
1 parent 9625436 commit f34f5c8

File tree

2 files changed

+53
-50
lines changed

2 files changed

+53
-50
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice
4949
*/
5050
private $configuredPriceSelection;
5151
/**
52-
* @var \Magento\Bundle\Pricing\Price\DiscountCalculator
52+
* @var DiscountCalculator
5353
*/
5454
private $discountCalculator;
5555

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

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
use Magento\Bundle\Pricing\Price\DiscountCalculator;
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
13-
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
14-
use Magento\Catalog\Model\Product\Option;
15-
use Magento\Catalog\Model\Product\Option\Type\DefaultType;
1613
use Magento\Bundle\Pricing\Price\ConfiguredPrice;
1714
use Magento\Bundle\Pricing\Adjustment\Calculator;
1815
use Magento\Catalog\Pricing\Price\ConfiguredPriceSelection;
@@ -33,53 +30,57 @@ class ConfiguredPriceTest extends TestCase
3330
/**
3431
* @var float
3532
*/
36-
protected $basePriceValue = 100.;
33+
private $basePriceValue = 100.;
3734

3835
/**
39-
* @var MockObject
36+
* @var ItemInterface|MockObject
4037
*/
41-
protected $item;
38+
private $itemMock;
4239

4340
/**
44-
* @var MockObject
41+
* @var Product|MockObject
4542
*/
46-
protected $product;
43+
private $productMock;
4744

4845
/**
4946
* @var MockObject
5047
*/
51-
protected $calculator;
48+
private $calculator;
5249

5350
/**
54-
* @var MockObject
51+
* @var Base|MockObject
5552
*/
56-
protected $priceInfo;
53+
private $priceInfoMock;
5754

5855
/**
5956
* @var ConfiguredPrice
6057
*/
61-
protected $model;
58+
private $model;
6259

6360
/**
6461
* @var PriceCurrencyInterface|MockObject
6562
*/
66-
protected $priceCurrencyMock;
63+
private $priceCurrencyMock;
64+
6765
/**
6866
* @var Json|MockObject
6967
*/
7068
private $jsonSerializerMock;
69+
7170
/**
7271
* @var ConfiguredPriceSelection|MockObject
7372
*/
7473
private $configuredPriceSelectionMock;
74+
7575
/**
7676
* @var AmountInterface|MockObject
7777
*/
7878
private $amountInterfaceMock;
79+
7980
/**
8081
* @var DiscountCalculator|MockObject
8182
*/
82-
private $discountCalculator;
83+
private $discountCalculatorMock;
8384

8485
/**
8586
* Initialize base dependencies
@@ -89,18 +90,18 @@ protected function setUp(): void
8990
$basePrice = $this->getMockForAbstractClass(PriceInterface::class);
9091
$basePrice->expects($this->any())->method('getValue')->willReturn($this->basePriceValue);
9192

92-
$this->priceInfo = $this->createMock(Base::class);
93-
$this->priceInfo->expects($this->any())->method('getPrice')->willReturn($basePrice);
94-
$this->product = $this->getMockBuilder(Product::class)
93+
$this->priceInfoMock = $this->createMock(Base::class);
94+
$this->priceInfoMock->expects($this->any())->method('getPrice')->willReturn($basePrice);
95+
$this->productMock = $this->getMockBuilder(Product::class)
9596
->setMethods(['getPriceInfo', 'getOptionById', 'getResource', 'getId'])
9697
->disableOriginalConstructor()
9798
->getMock();
98-
$this->product->expects($this->once())->method('getPriceInfo')->willReturn($this->priceInfo);
99-
$this->product->expects($this->any())->method('getId')->willReturn(123);
99+
$this->productMock->expects($this->once())->method('getPriceInfo')->willReturn($this->priceInfoMock);
100+
$this->productMock->expects($this->any())->method('getId')->willReturn(123);
100101

101-
$this->item = $this->getMockBuilder(ItemInterface::class)
102+
$this->itemMock = $this->getMockBuilder(ItemInterface::class)
102103
->getMock();
103-
$this->item->expects($this->any())->method('getProduct')->willReturn($this->product);
104+
$this->itemMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
104105

105106
$this->priceCurrencyMock = $this->getMockForAbstractClass(PriceCurrencyInterface::class);
106107

@@ -120,42 +121,28 @@ protected function setUp(): void
120121
->getMock();
121122
$this->calculator->expects($this->any())->method('calculateBundleAmount')
122123
->willReturn($this->amountInterfaceMock);
123-
$this->discountCalculator = $this->getMockBuilder(DiscountCalculator::class)
124+
$this->discountCalculatorMock = $this->getMockBuilder(DiscountCalculator::class)
124125
->disableOriginalConstructor()
125126
->getMock();
126-
$this->discountCalculator->expects($this->any())->method('calculateDiscount')
127+
$this->discountCalculatorMock->expects($this->any())->method('calculateDiscount')
127128
->willReturn(-5.0);
128129
$this->model = new ConfiguredPrice(
129-
$this->product,
130+
$this->productMock,
130131
1,
131132
$this->calculator,
132133
$this->priceCurrencyMock,
133134
null,
134135
$this->jsonSerializerMock,
135136
$this->configuredPriceSelectionMock,
136-
$this->discountCalculator,
137+
$this->discountCalculatorMock,
137138
);
138-
$this->model->setItem($this->item);
139-
}
140-
141-
private function prepareAndReturnSelectionPriceDataStub()
142-
{
143-
$first = new DataObject();
144-
$first->setValue(2);
145-
$first->setQuantity(1);
146-
$second = new DataObject();
147-
$second->setValue(3);
148-
$second->setQuantity(1);
149-
return [
150-
$first,
151-
$second
152-
];
139+
$this->model->setItem($this->itemMock);
153140
}
154141

155142
/**
156143
* Test of value getter when item presented
157144
*/
158-
public function testGetValueMethod()
145+
public function testGetValueMethod(): void
159146
{
160147
$valueFromMock = $this->model->getValue();
161148
$this->assertEquals(95., $valueFromMock);
@@ -164,19 +151,35 @@ public function testGetValueMethod()
164151
/**
165152
* Test of value getter if no product item
166153
*/
167-
public function testGetValueMethodNoItem()
154+
public function testGetValueMethodNoItem(): void
168155
{
169-
unset($this->item);
170-
$this->product = $this->getMockBuilder(Product::class)
171-
//->setMethods(['getPriceInfo', 'getOptionById', 'getResource', 'getId'])
156+
$this->productMock = $this->getMockBuilder(Product::class)
172157
->disableOriginalConstructor()
173158
->getMock();
174-
$this->item = $this->getMockBuilder(ItemInterface::class)
159+
$this->itemMock = $this->getMockBuilder(ItemInterface::class)
175160
->getMock();
176-
$this->item->expects($this->any())->method('getProduct')->willReturn($this->product);
177-
$this->product->expects($this->any())->method('getId')->willReturn(false);
178-
$this->model->setItem($this->item);
161+
$this->itemMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
162+
$this->productMock->expects($this->any())->method('getId')->willReturn(false);
163+
$this->model->setItem($this->itemMock);
179164
$valueFromMock = $this->model->getValue();
180165
$this->assertEquals(100., $valueFromMock);
181166
}
167+
168+
/**
169+
* Stub data for calculation amount of bundle
170+
* @return \Magento\Framework\DataObject[]
171+
*/
172+
private function prepareAndReturnSelectionPriceDataStub(): array
173+
{
174+
$first = new DataObject();
175+
$first->setValue(2);
176+
$first->setQuantity(1);
177+
$second = new DataObject();
178+
$second->setValue(3);
179+
$second->setQuantity(1);
180+
return [
181+
$first,
182+
$second
183+
];
184+
}
182185
}

0 commit comments

Comments
 (0)