Skip to content

Commit 1aa93e0

Browse files
committed
#33334:Inheriting from a class that doesn't exist
- Update the unit test for getter in case non-existing the item
1 parent b0c2133 commit 1aa93e0

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ protected function setUp(): void
9292
$this->priceInfo = $this->createMock(Base::class);
9393
$this->priceInfo->expects($this->any())->method('getPrice')->willReturn($basePrice);
9494
$this->product = $this->getMockBuilder(Product::class)
95-
->setMethods(['getPriceInfo', 'getOptionById', 'getResource'])
95+
->setMethods(['getPriceInfo', 'getOptionById', 'getResource', 'getId'])
9696
->disableOriginalConstructor()
9797
->getMock();
9898
$this->product->expects($this->once())->method('getPriceInfo')->willReturn($this->priceInfo);
99+
$this->product->expects($this->any())->method('getId')->willReturn(123);
99100

100101
$this->item = $this->getMockBuilder(ItemInterface::class)
101102
->getMock();
@@ -124,7 +125,16 @@ protected function setUp(): void
124125
->getMock();
125126
$this->discountCalculator->expects($this->any())->method('calculateDiscount')
126127
->willReturn(-5.0);
127-
$this->model = new ConfiguredPrice($this->product, 1, $this->calculator, $this->priceCurrencyMock, $this->discountCalculator,null, $this->jsonSerializerMock, $this->configuredPriceSelectionMock);
128+
$this->model = new ConfiguredPrice(
129+
$this->product,
130+
1,
131+
$this->calculator,
132+
$this->priceCurrencyMock,
133+
$this->discountCalculator,
134+
null,
135+
$this->jsonSerializerMock,
136+
$this->configuredPriceSelectionMock
137+
);
128138
$this->model->setItem($this->item);
129139
}
130140

@@ -141,6 +151,7 @@ private function prepareAndReturnSelectionPriceDataStub()
141151
$second
142152
];
143153
}
154+
144155
/**
145156
* Test of value getter
146157
*/
@@ -149,4 +160,23 @@ public function testGetValueMethod()
149160
$valueFromMock = $this->model->getValue();
150161
$this->assertEquals(95., $valueFromMock);
151162
}
163+
164+
/**
165+
* Test of value getter if no product item
166+
*/
167+
public function testGetValueMethodNoItem()
168+
{
169+
unset($this->item);
170+
$this->product = $this->getMockBuilder(Product::class)
171+
//->setMethods(['getPriceInfo', 'getOptionById', 'getResource', 'getId'])
172+
->disableOriginalConstructor()
173+
->getMock();
174+
$this->item = $this->getMockBuilder(ItemInterface::class)
175+
->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);
179+
$valueFromMock = $this->model->getValue();
180+
$this->assertEquals(100., $valueFromMock);
181+
}
152182
}

0 commit comments

Comments
 (0)