|
27 | 27 | use Magento\Store\Model\Store;
|
28 | 28 | use PHPUnit\Framework\MockObject\MockObject;
|
29 | 29 | use PHPUnit\Framework\TestCase;
|
| 30 | +use Magento\Quote\Api\Data\CartExtensionInterface; |
| 31 | +use Magento\Sales\Model\Order\ShippingAssignmentBuilder; |
| 32 | +use Magento\Quote\Api\Data\ShippingInterface; |
30 | 33 |
|
31 | 34 | /**
|
32 | 35 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
@@ -103,6 +106,21 @@ class ShippingMethodManagementTest extends TestCase
|
103 | 106 | */
|
104 | 107 | private $quoteAddressResource;
|
105 | 108 |
|
| 109 | + /** |
| 110 | + * @var CartExtensionInterface|MockObject |
| 111 | + */ |
| 112 | + private $extensionAttributesMock; |
| 113 | + |
| 114 | + /** |
| 115 | + * @var ShippingInterface|MockObject |
| 116 | + */ |
| 117 | + private $shippingMock; |
| 118 | + |
| 119 | + /** |
| 120 | + * @var ShippingAssignmentBuilder|MockObject |
| 121 | + */ |
| 122 | + private $shippingAssignmentBuilder; |
| 123 | + |
106 | 124 | protected function setUp(): void
|
107 | 125 | {
|
108 | 126 | $this->objectManager = new ObjectManager($this);
|
@@ -135,6 +153,7 @@ protected function setUp(): void
|
135 | 153 | 'collectTotals',
|
136 | 154 | 'save',
|
137 | 155 | '__wakeup',
|
| 156 | + 'getExtensionAttributes' |
138 | 157 | ])
|
139 | 158 | ->getMock();
|
140 | 159 |
|
@@ -190,6 +209,20 @@ protected function setUp(): void
|
190 | 209 | 'dataProcessor',
|
191 | 210 | $this->dataProcessor
|
192 | 211 | );
|
| 212 | + |
| 213 | + $this->extensionAttributesMock = $this->getMockBuilder(CartExtensionInterface::class) |
| 214 | + ->setMethods(['getShippingAssignments']) |
| 215 | + ->getMockForAbstractClass(); |
| 216 | + |
| 217 | + $this->shippingMock = $this->getMockForAbstractClass(ShippingInterface::class); |
| 218 | + |
| 219 | + $this->shippingAssignmentBuilder = $this->getMockBuilder(ShippingAssignmentBuilder::class) |
| 220 | + ->disableOriginalConstructor() |
| 221 | + ->setMethods([ |
| 222 | + 'getShipping', |
| 223 | + 'setShipping' |
| 224 | + ]) |
| 225 | + ->getMock(); |
193 | 226 | }
|
194 | 227 |
|
195 | 228 | public function testGetMethodWhenShippingAddressIsNotSet()
|
@@ -424,6 +457,24 @@ public function testSetMethodWithCouldNotSaveException()
|
424 | 457 | $this->shippingAddress->expects($this->once())
|
425 | 458 | ->method('setShippingMethod')
|
426 | 459 | ->with($carrierCode . '_' . $methodCode);
|
| 460 | + $this->quote->expects($this->once()) |
| 461 | + ->method('getExtensionAttributes') |
| 462 | + ->willReturn($this->extensionAttributesMock); |
| 463 | + |
| 464 | + $this->extensionAttributesMock->expects($this->once())->method('getShippingAssignments') |
| 465 | + ->willReturn([$this->shippingAssignmentBuilder]); |
| 466 | + |
| 467 | + $this->shippingAssignmentBuilder->expects($this->once())->method('getShipping') |
| 468 | + ->willReturn($this->shippingMock); |
| 469 | + |
| 470 | + $this->shippingMock->expects($this->once()) |
| 471 | + ->method('setMethod') |
| 472 | + ->with($carrierCode . '_' . $methodCode); |
| 473 | + |
| 474 | + $this->shippingAssignmentBuilder->expects($this->once()) |
| 475 | + ->method('setShipping') |
| 476 | + ->with($this->shippingMock); |
| 477 | + |
427 | 478 | $exception = new \Exception('Custom Error');
|
428 | 479 | $this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
|
429 | 480 | $this->quoteRepository->expects($this->once())
|
@@ -477,6 +528,24 @@ public function testSetMethod()
|
477 | 528 | ->method('getCountryId')->willReturn($countryId);
|
478 | 529 | $this->shippingAddress->expects($this->once())
|
479 | 530 | ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode);
|
| 531 | + $this->quote->expects($this->once()) |
| 532 | + ->method('getExtensionAttributes') |
| 533 | + ->willReturn($this->extensionAttributesMock); |
| 534 | + |
| 535 | + $this->extensionAttributesMock->expects($this->once())->method('getShippingAssignments') |
| 536 | + ->willReturn([$this->shippingAssignmentBuilder]); |
| 537 | + |
| 538 | + $this->shippingAssignmentBuilder->expects($this->once())->method('getShipping') |
| 539 | + ->willReturn($this->shippingMock); |
| 540 | + |
| 541 | + $this->shippingMock->expects($this->once()) |
| 542 | + ->method('setMethod') |
| 543 | + ->with($carrierCode . '_' . $methodCode); |
| 544 | + |
| 545 | + $this->shippingAssignmentBuilder->expects($this->once()) |
| 546 | + ->method('setShipping') |
| 547 | + ->with($this->shippingMock); |
| 548 | + |
480 | 549 | $this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
|
481 | 550 | $this->quoteRepository->expects($this->once())->method('save')->with($this->quote);
|
482 | 551 |
|
|
0 commit comments