108 $this->creditmemoMock = $this->getMockBuilder(\
Magento\Sales\Model\Order\Creditmemo::class)
109 ->disableOriginalConstructor()
110 ->setMethods([
'getInvoice',
'getOrder',
'cancel',
'getId',
'__wakeup'])
112 $titleMock = $this->getMockBuilder(\
Magento\Framework\
App\Action\Title::class)
113 ->disableOriginalConstructor()
115 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
116 ->disableOriginalConstructor()
118 $this->responseMock = $this->getMockBuilder(\
Magento\Framework\
App\
Response\Http::class)
119 ->disableOriginalConstructor()
121 $this->objectManagerMock = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
122 $this->messageManagerMock = $this->getMockBuilder(\
Magento\Framework\Message\Manager::class)
123 ->disableOriginalConstructor()
125 $this->sessionMock = $this->getMockBuilder(\
Magento\Backend\Model\Session::class)
126 ->disableOriginalConstructor()
128 $this->helperMock = $this->getMockBuilder(\
Magento\Backend\Helper\Data::class)
129 ->disableOriginalConstructor()
131 $this->contextMock = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
142 'getResultRedirectFactory' 145 ->disableOriginalConstructor()
147 $this->contextMock->expects($this->any())
148 ->method(
'getHelper')
149 ->will($this->returnValue($this->helperMock));
150 $this->actionFlagMock = $this->getMockBuilder(\
Magento\Framework\
App\ActionFlag::class)
151 ->disableOriginalConstructor()
153 $this->contextMock->expects($this->any())
154 ->method(
'getSession')
155 ->will($this->returnValue($this->sessionMock));
156 $this->contextMock->expects($this->any())
157 ->method(
'getActionFlag')
158 ->will($this->returnValue($this->actionFlagMock));
159 $this->contextMock->expects($this->any())
160 ->method(
'getRequest')
161 ->will($this->returnValue($this->requestMock));
162 $this->contextMock->expects($this->any())
163 ->method(
'getResponse')
164 ->will($this->returnValue($this->responseMock));
165 $this->contextMock->expects($this->any())
166 ->method(
'getObjectManager')
167 ->will($this->returnValue($this->objectManagerMock));
168 $this->contextMock->expects($this->any())
170 ->will($this->returnValue($titleMock));
171 $this->contextMock->expects($this->any())
172 ->method(
'getMessageManager')
173 ->will($this->returnValue($this->messageManagerMock));
174 $this->loaderMock = $this->getMockBuilder(\
Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader::class)
175 ->disableOriginalConstructor()
177 $this->resultPageFactoryMock = $this->getMockBuilder(\
Magento\Framework\View\Result\PageFactory::class)
178 ->disableOriginalConstructor()
179 ->setMethods([
'create'])
181 $this->resultJsonFactoryMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\JsonFactory::class)
182 ->disableOriginalConstructor()
183 ->setMethods([
'create'])
185 $this->resultRawFactoryMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\RawFactory::class)
186 ->disableOriginalConstructor()
187 ->setMethods([
'create'])
189 $this->resultPageMock = $this->getMockBuilder(\
Magento\Backend\Model\View\Result\Page::class)
190 ->disableOriginalConstructor()
192 $this->resultJsonMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
193 ->disableOriginalConstructor()
195 $this->resultRawMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Raw::class)
196 ->disableOriginalConstructor()
199 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
201 \
Magento\Sales\Controller\Adminhtml\Order\Creditmemo\UpdateQty::class,
203 'context' => $this->contextMock,
204 'creditmemoLoader' => $this->loaderMock,
205 'resultPageFactory' => $this->resultPageFactoryMock,
206 'resultJsonFactory' => $this->resultJsonFactoryMock,
207 'resultRawFactory' => $this->resultRawFactoryMock
220 $e = new \Magento\Framework\Exception\LocalizedException(
__(
$message));
223 $this->requestMock->expects($this->any())
225 ->willReturnArgument(0);
226 $this->loaderMock->expects($this->once())
228 ->willThrowException($e);
229 $this->resultJsonFactoryMock->expects($this->once())
231 ->willReturn($this->resultJsonMock);
232 $this->resultJsonMock->expects($this->once())
237 $this->assertInstanceOf(
238 \
Magento\Framework\Controller\Result\Json::class,
239 $this->controller->execute()
250 $message =
'We can\'t update the item\'s quantity right now.';
254 $this->requestMock->expects($this->any())
256 ->willReturnArgument(0);
257 $this->loaderMock->expects($this->once())
259 ->willThrowException($e);
260 $this->resultJsonFactoryMock->expects($this->once())
262 ->willReturn($this->resultJsonMock);
263 $this->resultJsonMock->expects($this->once())
268 $this->assertInstanceOf(
269 \
Magento\Framework\Controller\Result\Json::class,
270 $this->controller->execute()
283 $this->requestMock->expects($this->any())
285 ->withAnyParameters()
286 ->willReturnArgument(0);
288 $layoutMock = $this->getMockBuilder(\
Magento\Framework\View\Layout::class)
289 ->disableOriginalConstructor()
291 $blockMock = $this->getMockBuilder(\
Magento\Sales\Block\Order\Items::class)
292 ->disableOriginalConstructor()
295 $this->resultPageFactoryMock->expects($this->once())
297 ->willReturn($this->resultPageMock);
298 $this->resultPageMock->expects($this->atLeastOnce())
299 ->method(
'getLayout')
300 ->willReturn($layoutMock);
301 $blockMock->expects($this->once())
304 $layoutMock->expects($this->once())
306 ->with(
'order_items')
307 ->willReturn($blockMock);
308 $this->resultRawFactoryMock->expects($this->once())
310 ->willReturn($this->resultRawMock);
311 $this->resultRawMock->expects($this->once())
312 ->method(
'setContents')
316 $this->assertInstanceOf(
317 \
Magento\Framework\Controller\Result\Raw::class,
318 $this->controller->execute()
testExecuteModelException()