55 $this->shipmentLoaderMock = $this->createPartialMock(
56 \
Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader::class,
57 [
'setOrderId',
'setShipmentId',
'setShipment',
'setTracking',
'load',
'__wakeup']
59 $this->shipmentMock = $this->createPartialMock(
60 \
Magento\Sales\Model\Order\Shipment::class,
63 $this->requestMock = $this->createPartialMock(
65 [
'getParam',
'__wakeup']
67 $this->responseMock = $this->createPartialMock(
69 [
'representJson',
'__wakeup']
71 $this->objectManagerMock = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
72 $this->messageManagerMock = $this->createPartialMock(
73 \
Magento\Framework\Message\Manager::class,
74 [
'addSuccess',
'addError',
'__wakeup']
76 $this->labelGenerator = $this->createPartialMock(
77 \
Magento\Shipping\Model\Shipping\LabelGenerator::class,
78 [
'create',
'__wakeup']
81 $contextMock = $this->createPartialMock(
83 [
'getRequest',
'getResponse',
'getMessageManager',
'getActionFlag',
'getObjectManager',
'__wakeup']
87 $contextMock->expects($this->any())->method(
'getRequest')->will($this->returnValue($this->requestMock));
88 $contextMock->expects($this->any())->method(
'getResponse')->will($this->returnValue($this->responseMock));
89 $contextMock->expects($this->any())
90 ->method(
'getObjectManager')
91 ->will($this->returnValue($this->objectManagerMock));
92 $contextMock->expects($this->any())
93 ->method(
'getMessageManager')
94 ->will($this->returnValue($this->messageManagerMock));
96 $this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\CreateLabel(
98 $this->shipmentLoaderMock,
115 $this->requestMock->expects($this->at(0))
118 ->will($this->returnValue($orderId));
119 $this->requestMock->expects($this->at(1))
121 ->with(
'shipment_id')
122 ->will($this->returnValue($shipmentId));
123 $this->requestMock->expects($this->at(2))
127 $this->requestMock->expects($this->at(3))
130 ->will($this->returnValue($tracking));
131 $this->shipmentLoaderMock->expects($this->once())
132 ->method(
'setOrderId')
134 $this->shipmentLoaderMock->expects($this->once())
135 ->method(
'setShipmentId')
137 $this->shipmentLoaderMock->expects($this->once())
138 ->method(
'setShipment')
140 $this->shipmentLoaderMock->expects($this->once())
141 ->method(
'setTracking')
150 $this->shipmentLoaderMock->expects($this->once())
152 ->will($this->returnValue($this->shipmentMock));
153 $this->labelGenerator->expects($this->once())
155 ->with($this->shipmentMock, $this->requestMock)
156 ->will($this->returnValue(
true));
157 $this->shipmentMock->expects($this->once())->method(
'save')->will($this->returnSelf());
158 $this->messageManagerMock->expects($this->once())->method(
'addSuccess');
159 $this->responseMock->expects($this->once())->method(
'representJson');
161 $this->assertNull($this->controller->execute());
169 $this->shipmentLoaderMock->expects($this->once())
171 ->willThrowException(
new \
Magento\Framework\Exception\LocalizedException(
__(
'message')));
172 $this->responseMock->expects($this->once())->method(
'representJson');
174 $this->assertNull($this->controller->execute());
182 $loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
184 $this->shipmentLoaderMock->expects($this->once())
186 ->will($this->returnValue($this->shipmentMock));
187 $this->labelGenerator->expects($this->once())
189 ->with($this->shipmentMock, $this->requestMock)
190 ->will($this->returnValue(
true));
191 $this->shipmentMock->expects($this->once())->method(
'save')->will($this->throwException(
new \Exception()));
192 $loggerMock->expects($this->once())->method(
'critical');
193 $this->objectManagerMock->expects($this->once())
195 ->with(\Psr\Log\LoggerInterface::class)
196 ->will($this->returnValue($loggerMock));
197 $this->responseMock->expects($this->once())->method(
'representJson');
199 $this->assertNull($this->controller->execute());
207 $this->shipmentLoaderMock->expects($this->once())
209 ->will($this->returnValue($this->shipmentMock));
210 $this->labelGenerator->expects($this->once())
212 ->with($this->shipmentMock, $this->requestMock)
213 ->willThrowException(
214 new \
Magento\Framework\Exception\LocalizedException(
__(
'message'))
216 $this->responseMock->expects($this->once())->method(
'representJson');
218 $this->assertNull($this->controller->execute());
testExecuteLabelGenerateFail()
testExecuteLoadException()
testExecuteSaveException()
foreach($order->getItems() as $orderItem) $shipment