Skip to content

Commit 94f59b4

Browse files
committed
MAGETWO-56431: Shipment creation through API change order status. Back port for 2.1.x
1 parent 182988f commit 94f59b4

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/Validation/QuantityValidatorTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public function testValidateTrackWithoutOrderId()
4545
$this->shipmentMock->expects($this->once())
4646
->method('getOrderId')
4747
->willReturn(null);
48-
$this->assertEquals([__('Order Id is required for shipment document')], $this->validator->validate($this->shipmentMock));
48+
$this->assertEquals(
49+
[__('Order Id is required for shipment document')],
50+
$this->validator->validate($this->shipmentMock)
51+
);
4952
}
5053

5154
public function testValidateTrackWithoutItems()
@@ -56,6 +59,9 @@ public function testValidateTrackWithoutItems()
5659
$this->shipmentMock->expects($this->once())
5760
->method('getItems')
5861
->willReturn(null);
59-
$this->assertEquals([__('You can\'t create a shipment without products.')], $this->validator->validate($this->shipmentMock));
62+
$this->assertEquals(
63+
[__('You can\'t create a shipment without products.')],
64+
$this->validator->validate($this->shipmentMock)
65+
);
6066
}
6167
}

app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;
88

99
use Magento\Backend\App\Action;
10-
use Magento\Framework\App\ObjectManager;
1110
use Magento\Sales\Model\Order\Shipment\Validation\QuantityValidator;
1211

1312
/**
@@ -193,7 +192,7 @@ public function execute()
193192
private function getShipmentValidator()
194193
{
195194
if ($this->shipmentValidator === null) {
196-
$this->shipmentValidator = ObjectManager::getInstance()->get(
195+
$this->shipmentValidator = $this->_objectManager->get(
197196
\Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface::class
198197
);
199198
}

app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/SaveTest.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,22 @@ class SaveTest extends \PHPUnit_Framework_TestCase
102102
protected function setUp()
103103
{
104104
$objectManagerHelper = new ObjectManagerHelper($this);
105-
$this->shipmentLoader = $this->getMockBuilder('Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader')
105+
$this->shipmentLoader = $this->getMockBuilder(
106+
\Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader::class)
106107
->disableOriginalConstructor()
107108
->setMethods([])
108109
->getMock();
109-
$this->labelGenerator = $this->getMockBuilder('Magento\Shipping\Model\Shipping\LabelGenerator')
110+
$this->labelGenerator = $this->getMockBuilder(\Magento\Shipping\Model\Shipping\LabelGenerator::class)
110111
->disableOriginalConstructor()
111112
->setMethods([])
112113
->getMock();
113-
$this->shipmentSender = $this->getMockBuilder('Magento\Sales\Model\Order\Email\Sender\ShipmentSender')
114+
$this->shipmentSender = $this->getMockBuilder(\Magento\Sales\Model\Order\Email\Sender\ShipmentSender::class)
114115
->disableOriginalConstructor()
115116
->setMethods([])
116117
->getMock();
117-
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
118+
$this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class);
118119
$this->context = $this->getMock(
119-
'Magento\Backend\App\Action\Context',
120+
\Magento\Backend\App\Action\Context::class,
120121
[
121122
'getRequest', 'getResponse', 'getMessageManager', 'getRedirect',
122123
'getObjectManager', 'getSession', 'getActionFlag', 'getHelper',
@@ -127,40 +128,40 @@ protected function setUp()
127128
false
128129
);
129130
$this->response = $this->getMock(
130-
'Magento\Framework\App\ResponseInterface',
131+
\Magento\Framework\App\ResponseInterface::class,
131132
['setRedirect', 'sendResponse'],
132133
[],
133134
'',
134135
false
135136
);
136-
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
137+
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
137138
->disableOriginalConstructor()->getMock();
138139
$this->objectManager = $this->getMock(
139-
'Magento\Framework\ObjectManager\ObjectManager',
140+
\Magento\Framework\ObjectManager\ObjectManager::class,
140141
['create', 'get'],
141142
[],
142143
'',
143144
false
144145
);
145146
$this->messageManager = $this->getMock(
146-
'Magento\Framework\Message\Manager',
147+
\Magento\Framework\Message\Manager::class,
147148
['addSuccess', 'addError'],
148149
[],
149150
'',
150151
false
151152
);
152153
$this->session = $this->getMock(
153-
'Magento\Backend\Model\Session',
154+
\Magento\Backend\Model\Session::class,
154155
['setIsUrlNotice', 'getCommentText'],
155156
[],
156157
'',
157158
false
158159
);
159-
$this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', ['get'], [], '', false);
160-
$this->helper = $this->getMock('Magento\Backend\Helper\Data', ['getUrl'], [], '', false);
160+
$this->actionFlag = $this->getMock(\Magento\Framework\App\ActionFlag::class, ['get'], [], '', false);
161+
$this->helper = $this->getMock(\Magento\Backend\Helper\Data::class, ['getUrl'], [], '', false);
161162

162163
$this->resultRedirect = $this->getMock(
163-
'Magento\Framework\Controller\Result\Redirect',
164+
\Magento\Framework\Controller\Result\Redirect::class,
164165
['setPath'],
165166
[],
166167
'',
@@ -171,7 +172,7 @@ protected function setUp()
171172
->willReturn($this->resultRedirect);
172173

173174
$resultRedirectFactory = $this->getMock(
174-
'Magento\Framework\Controller\Result\RedirectFactory',
175+
\Magento\Framework\Controller\Result\RedirectFactory::class,
175176
['create'],
176177
[],
177178
'',
@@ -182,7 +183,7 @@ protected function setUp()
182183
->willReturn($this->resultRedirect);
183184

184185
$this->formKeyValidator = $this->getMock(
185-
'Magento\Framework\Data\Form\FormKey\Validator',
186+
\Magento\Framework\Data\Form\FormKey\Validator::class,
186187
['validate'],
187188
[],
188189
'',
@@ -222,7 +223,7 @@ protected function setUp()
222223
->getMock();
223224

224225
$this->saveAction = $objectManagerHelper->getObject(
225-
'Magento\Shipping\Controller\Adminhtml\Order\Shipment\Save',
226+
\Magento\Shipping\Controller\Adminhtml\Order\Shipment\Save::class,
226227
[
227228
'labelGenerator' => $this->labelGenerator,
228229
'shipmentSender' => $this->shipmentSender,
@@ -250,7 +251,6 @@ public function testExecute($formKeyIsValid, $isPost)
250251
$this->request->expects($this->any())
251252
->method('isPost')
252253
->willReturn($isPost);
253-
254254
if (!$formKeyIsValid || !$isPost) {
255255
$this->messageManager->expects($this->once())
256256
->method('addError');
@@ -269,14 +269,14 @@ public function testExecute($formKeyIsValid, $isPost)
269269
$tracking = [];
270270
$shipmentData = ['items' => [], 'send_email' => ''];
271271
$shipment = $this->getMock(
272-
'Magento\Sales\Model\Order\Shipment',
272+
\Magento\Sales\Model\Order\Shipment::class,
273273
['load', 'save', 'register', 'getOrder', 'getOrderId', '__wakeup'],
274274
[],
275275
'',
276276
false
277277
);
278278
$order = $this->getMock(
279-
'Magento\Sales\Model\Order',
279+
\Magento\Sales\Model\Order::class,
280280
['setCustomerNoteNotify', '__wakeup'],
281281
[],
282282
'',
@@ -324,7 +324,7 @@ public function testExecute($formKeyIsValid, $isPost)
324324
->method('create')
325325
->with($shipment, $this->request)
326326
->will($this->returnValue(true));
327-
$saveTransaction = $this->getMockBuilder('Magento\Framework\DB\Transaction')
327+
$saveTransaction = $this->getMockBuilder(\Magento\Framework\DB\Transaction::class)
328328
->disableOriginalConstructor()
329329
->setMethods([])
330330
->getMock();
@@ -342,15 +342,17 @@ public function testExecute($formKeyIsValid, $isPost)
342342
$this->session->expects($this->once())
343343
->method('getCommentText')
344344
->with(true);
345-
346345
$this->objectManager->expects($this->once())
347346
->method('create')
348-
->with('Magento\Framework\DB\Transaction')
347+
->with(\Magento\Framework\DB\Transaction::class)
349348
->will($this->returnValue($saveTransaction));
350-
$this->objectManager->expects($this->once())
349+
$this->objectManager->expects($this->exactly(2))
351350
->method('get')
352-
->with('Magento\Backend\Model\Session')
353-
->will($this->returnValue($this->session));
351+
->withConsecutive(
352+
[\Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface::class],
353+
[\Magento\Backend\Model\Session::class]
354+
)
355+
->willReturnOnConsecutiveCalls($this->shipmentValidatorMock, $this->session);
354356
$path = 'sales/order/view';
355357
$arguments = ['order_id' => $orderId];
356358
$shipment->expects($this->once())

0 commit comments

Comments
 (0)