Skip to content

Commit b4908c1

Browse files
committed
MAGETWO-56429: Shipment creation through API change order status. Back port for 2.0.x
1 parent 83d6a78 commit b4908c1

File tree

2 files changed

+29
-28
lines changed
  • app/code/Magento/Shipping
    • Controller/Adminhtml/Order/Shipment
    • Test/Unit/Controller/Adminhtml/Order/Shipment

2 files changed

+29
-28
lines changed

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
/**
@@ -194,7 +193,7 @@ public function execute()
194193
private function getShipmentValidator()
195194
{
196195
if ($this->shipmentValidator === null) {
197-
$this->shipmentValidator = ObjectManager::getInstance()->get(
196+
$this->shipmentValidator = $this->_objectManager->get(
198197
\Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface::class
199198
);
200199
}

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

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,25 @@ class SaveTest extends \PHPUnit_Framework_TestCase
9999
/**
100100
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
101101
*/
102-
public function setUp()
102+
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 @@ public 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 @@ public 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 @@ public 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 @@ public 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)