10 use Magento\Quote\Model\ShippingAssignmentFactory;
26 private $shippingAssignmentProcessor;
31 private $objectManagerHelper;
36 private $shippingAssignmentFactoryMock;
41 private $shippingProcessorMock;
46 private $cartItemPersisterMock;
51 private $addressRepositoryMock;
61 private $shippingAssignmentMock;
66 private $shippingAddressMock;
71 private $shippingMock;
75 $this->shippingAssignmentFactoryMock = $this->getMockBuilder(ShippingAssignmentFactory::class)
76 ->disableOriginalConstructor()
78 $this->shippingProcessorMock = $this->getMockBuilder(ShippingProcessor::class)
79 ->disableOriginalConstructor()
81 $this->cartItemPersisterMock = $this->getMockBuilder(CartItemPersister::class)
82 ->disableOriginalConstructor()
84 $this->addressRepositoryMock = $this->getMockBuilder(AddressRepositoryInterface::class)
85 ->getMockForAbstractClass();
86 $this->quoteMock = $this->getMockBuilder(Quote::class)
87 ->disableOriginalConstructor()
89 $this->shippingAssignmentMock = $this->getMockBuilder(ShippingAssignmentInterface::class)
90 ->getMockForAbstractClass();
91 $this->shippingAddressMock = $this->getMockBuilder(QuoteAddress::class)
92 ->disableOriginalConstructor()
94 $this->shippingMock = $this->getMockBuilder(ShippingInterface::class)
95 ->getMockForAbstractClass();
97 $this->quoteMock->expects(static::any())
98 ->method(
'getShippingAddress')
99 ->willReturn($this->shippingAddressMock);
100 $this->shippingAssignmentMock->expects(static::any())
101 ->method(
'getShipping')
102 ->willReturn($this->shippingMock);
103 $this->shippingMock->expects(static::any())
104 ->method(
'getAddress')
105 ->willReturn($this->shippingAddressMock);
107 $this->objectManagerHelper =
new ObjectManagerHelper($this);
108 $this->shippingAssignmentProcessor = $this->objectManagerHelper->getObject(
109 ShippingAssignmentProcessor::class,
111 'shippingAssignmentFactory' => $this->shippingAssignmentFactoryMock,
112 'shippingProcessor' => $this->shippingProcessorMock,
113 'cartItemPersister' => $this->cartItemPersisterMock,
114 'addressRepository' => $this->addressRepositoryMock
123 $this->shippingAssignmentMock->expects(static::once())
125 ->willReturn([$this->createQuoteItemMock(
$quoteItemId,
true)]);
126 $this->quoteMock->expects(static::atLeastOnce())
127 ->method(
'getItemById')
130 $this->cartItemPersisterMock->expects(static::never())
132 $this->shippingAddressMock->expects(static::atLeastOnce())
133 ->method(
'getCustomerAddressId')
135 $this->addressRepositoryMock->expects(static::never())
137 $this->shippingProcessorMock->expects(static::once())
139 ->with($this->shippingMock, $this->quoteMock);
141 $this->shippingAssignmentProcessor->save($this->quoteMock, $this->shippingAssignmentMock);
146 $customerAddressId = 11;
148 $this->shippingAssignmentMock->expects(static::atLeastOnce())
151 $this->shippingAddressMock->expects(static::atLeastOnce())
152 ->method(
'getCustomerAddressId')
153 ->willReturn($customerAddressId);
154 $this->addressRepositoryMock->expects(static::once())
156 ->with($customerAddressId)
158 $this->shippingAddressMock->expects(static::once())
159 ->method(
'setCustomerAddressId')
161 ->willReturn($this->shippingAddressMock);
162 $this->shippingProcessorMock->expects(static::once())
164 ->with($this->shippingMock, $this->quoteMock);
166 $this->shippingAssignmentProcessor->save($this->quoteMock, $this->shippingAssignmentMock);
176 private function createQuoteItemMock(
$id, $isDeleted)
178 $quoteItemMock = $this->getMockBuilder(QuoteItem::class)
179 ->disableOriginalConstructor()
182 $quoteItemMock->expects(static::any())
183 ->method(
'getItemId')
185 $quoteItemMock->expects(static::any())
186 ->method(
'isDeleted')
187 ->willReturn($isDeleted);
189 return $quoteItemMock;
testSaveWithNotExistingCustomerAddress()
testSaveWithDeletedCartItems()