|
21 | 21 | use Magento\Store\Model\StoreManagerInterface; |
22 | 22 | use Magento\Store\Model\Website; |
23 | 23 | use PHPUnit\Framework\MockObject\MockObject; |
| 24 | +use PHPUnit\Framework\MockObject\RuntimeException; |
24 | 25 | use PHPUnit\Framework\TestCase; |
25 | 26 |
|
26 | 27 | /** |
@@ -289,14 +290,30 @@ function () { |
289 | 290 | return $this->objectManagerHelper->getObject(TierPrice::class); |
290 | 291 | } |
291 | 292 | ); |
292 | | - $tierPriceExtensionMock = $this->getMockBuilder(ProductTierPriceExtensionInterface::class) |
293 | | - ->onlyMethods(['getPercentageValue', 'setPercentageValue']) |
294 | | - ->getMockForAbstractClass(); |
| 293 | + $tierPriceExtensionMock = $this->getProductTierPriceExtensionInterfaceMock(); |
295 | 294 | $tierPriceExtensionMock->method('getPercentageValue') |
296 | 295 | ->willReturn(50); |
297 | 296 | $this->tierPriceExtensionFactoryMock->method('create') |
298 | 297 | ->willReturn($tierPriceExtensionMock); |
299 | 298 |
|
300 | 299 | $this->assertInstanceOf(TierPrice::class, $this->model->getTierPrices($this->product)[0]); |
301 | 300 | } |
| 301 | + |
| 302 | + /** |
| 303 | + * Build ProductTierPriceExtensionInterface mock. |
| 304 | + * |
| 305 | + * @return MockObject |
| 306 | + */ |
| 307 | + private function getProductTierPriceExtensionInterfaceMock(): MockObject |
| 308 | + { |
| 309 | + $mockBuilder = $this->getMockBuilder(ProductTierPriceExtensionInterface::class) |
| 310 | + ->disableOriginalConstructor(); |
| 311 | + try { |
| 312 | + $mockBuilder->addMethods(['getPercentageValue', 'setPercentageValue', 'setWebsiteId']); |
| 313 | + } catch (RuntimeException $e) { |
| 314 | + // ProductTierPriceExtensionInterface already generated and has all necessary methods. |
| 315 | + } |
| 316 | + |
| 317 | + return $mockBuilder->getMock(); |
| 318 | + } |
302 | 319 | } |
0 commit comments