Skip to content

Commit 6487a6b

Browse files
author
vpaladiychuk
committed
MAGETWO-32554: Refactor Adminhtml/order/invoice directory
1 parent a68f739 commit 6487a6b

File tree

5 files changed

+7
-66
lines changed

5 files changed

+7
-66
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddComment.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ public function execute()
101101
$response = ['error' => true, 'message' => __('Cannot add new comment.')];
102102
}
103103
if (is_array($response)) {
104-
$response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response);
105104
/** @var \Magento\Framework\Controller\Result\JSON $resultJson */
106105
$resultJson = $this->resultJsonFactory->create();
107-
$resultJson->setJsonData($response);
106+
$resultJson->setData($response);
108107
return $resultJson;
109108
} else {
110109
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function execute()
218218
}
219219
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
220220
$resultRedirect = $this->resultRedirectFactory->create();
221-
$resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
221+
$resultRedirect->setPath('sales/*/new', ['order_id' => $orderId]);
222222
return $resultRedirect;
223223
}
224224
}

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
class UpdateQty extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View
1818
{
19-
2019
/**
2120
* @var JSONFactory
2221
*/
@@ -97,10 +96,9 @@ public function execute()
9796
$response = ['error' => true, 'message' => __('Cannot update item quantity.')];
9897
}
9998
if (is_array($response)) {
100-
$response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response);
10199
/** @var \Magento\Framework\Controller\Result\JSON $resultJson */
102100
$resultJson = $this->resultJsonFactory->create();
103-
$resultJson->setJsonData($response);
101+
$resultJson->setData($response);
104102
return $resultJson;
105103
} else {
106104
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */

dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddCommentTest.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,11 @@ public function testExecuteModelException()
265265
->method('getParam')
266266
->will($this->throwException($e));
267267

268-
$helperMock = $this->getMockBuilder('Magento\Core\Helper\Data')
269-
->disableOriginalConstructor()
270-
->setMethods([])
271-
->getMock();
272-
$helperMock->expects($this->once())
273-
->method('jsonEncode')
274-
->with($response)
275-
->will($this->returnValue(json_encode($response)));
276-
277-
$this->objectManagerMock->expects($this->once())
278-
->method('get')
279-
->with('Magento\Core\Helper\Data')
280-
->will($this->returnValue($helperMock));
281-
282268
$this->resultJsonFactoryMock->expects($this->once())
283269
->method('create')
284270
->will($this->returnValue($this->resultJsonMock));
285271

286-
$this->resultJsonMock->expects($this->once())->method('setJsonData')->with(json_encode($response));
272+
$this->resultJsonMock->expects($this->once())->method('setData')->with($response);
287273
$this->assertSame($this->resultJsonMock, $this->controller->execute());
288274
}
289275

@@ -296,25 +282,11 @@ public function testExecuteException()
296282
->method('getParam')
297283
->will($this->throwException($e));
298284

299-
$helperMock = $this->getMockBuilder('Magento\Core\Helper\Data')
300-
->disableOriginalConstructor()
301-
->setMethods([])
302-
->getMock();
303-
$helperMock->expects($this->once())
304-
->method('jsonEncode')
305-
->with($response)
306-
->will($this->returnValue(json_encode($response)));
307-
308-
$this->objectManagerMock->expects($this->once())
309-
->method('get')
310-
->with('Magento\Core\Helper\Data')
311-
->will($this->returnValue($helperMock));
312-
313285
$this->resultJsonFactoryMock->expects($this->once())
314286
->method('create')
315287
->will($this->returnValue($this->resultJsonMock));
316288

317-
$this->resultJsonMock->expects($this->once())->method('setJsonData')->with(json_encode($response));
289+
$this->resultJsonMock->expects($this->once())->method('setData')->with($response);
318290
$this->assertSame($this->resultJsonMock, $this->controller->execute());
319291
}
320292
}

dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -271,26 +271,12 @@ public function testExecuteModelException()
271271
->method('prepend')
272272
->with('Invoices');
273273

274-
$helperMock = $this->getMockBuilder('Magento\Core\Helper\Data')
275-
->disableOriginalConstructor()
276-
->setMethods([])
277-
->getMock();
278-
$helperMock->expects($this->once())
279-
->method('jsonEncode')
280-
->with($response)
281-
->will($this->returnValue(json_encode($response)));
282-
283-
$this->objectManagerMock->expects($this->once())
284-
->method('get')
285-
->with('Magento\Core\Helper\Data')
286-
->will($this->returnValue($helperMock));
287-
288274
/** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */
289275
$resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON')
290276
->disableOriginalConstructor()
291277
->setMethods([])
292278
->getMock();
293-
$resultJsonMock->expects($this->once())->method('setJsonData')->with(json_encode($response));
279+
$resultJsonMock->expects($this->once())->method('setData')->with($response);
294280

295281
$this->resultJsonFactoryMock->expects($this->once())
296282
->method('create')
@@ -323,26 +309,12 @@ public function testExecuteException()
323309
->method('prepend')
324310
->with('Invoices');
325311

326-
$helperMock = $this->getMockBuilder('Magento\Core\Helper\Data')
327-
->disableOriginalConstructor()
328-
->setMethods([])
329-
->getMock();
330-
$helperMock->expects($this->once())
331-
->method('jsonEncode')
332-
->with($response)
333-
->will($this->returnValue(json_encode($response)));
334-
335-
$this->objectManagerMock->expects($this->once())
336-
->method('get')
337-
->with('Magento\Core\Helper\Data')
338-
->will($this->returnValue($helperMock));
339-
340312
/** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */
341313
$resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON')
342314
->disableOriginalConstructor()
343315
->setMethods([])
344316
->getMock();
345-
$resultJsonMock->expects($this->once())->method('setJsonData')->with(json_encode($response));
317+
$resultJsonMock->expects($this->once())->method('setData')->with($response);
346318

347319
$this->resultJsonFactoryMock->expects($this->once())
348320
->method('create')

0 commit comments

Comments
 (0)