@@ -171,6 +171,102 @@ public function testCreate($tracks)
171
171
$ this ->assertEquals ($ shipment , $ this ->subject ->create ($ order , ['1 ' => 5 ], $ tracks ));
172
172
}
173
173
174
+ /**
175
+ * @param array|null $tracks
176
+ * @dataProvider createDataProvider
177
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
178
+ */
179
+ public function testCreateWithFloatQtyShipment (?array $ tracks ): void
180
+ {
181
+ $ orderItem = $ this ->createPartialMock (
182
+ Item::class,
183
+ ['getId ' , 'getQtyOrdered ' , 'getParentItemId ' , 'getIsVirtual ' ,'getIsQtyDecimal ' ]
184
+ );
185
+ $ orderItem ->expects ($ this ->any ())
186
+ ->method ('getIsQtyDecimal ' )
187
+ ->willReturn (true );
188
+ $ orderItem ->expects ($ this ->any ())
189
+ ->method ('getId ' )
190
+ ->willReturn (1 );
191
+ $ orderItem ->expects ($ this ->any ())
192
+ ->method ('getQtyOrdered ' )
193
+ ->willReturn (0.5 );
194
+ $ orderItem ->expects ($ this ->any ())->method ('getParentItemId ' )->willReturn (false );
195
+ $ orderItem ->expects ($ this ->any ())->method ('getIsVirtual ' )->willReturn (false );
196
+
197
+ $ shipmentItem = $ this ->createPartialMock (
198
+ \Magento \Sales \Model \Order \Shipment \Item::class,
199
+ ['setQty ' , 'getOrderItem ' , 'getQty ' ]
200
+ );
201
+ $ shipmentItem ->expects ($ this ->once ())
202
+ ->method ('setQty ' )
203
+ ->with (0.5 );
204
+ $ shipmentItem ->expects ($ this ->once ())
205
+ ->method ('getQty ' )
206
+ ->willReturn (0.5 );
207
+
208
+ $ shipmentItem ->expects ($ this ->atLeastOnce ())->method ('getOrderItem ' )->willReturn ($ orderItem );
209
+
210
+ $ order = $ this ->createPartialMock (\Magento \Sales \Model \Order::class, ['getAllItems ' ]);
211
+ $ order ->expects ($ this ->any ())
212
+ ->method ('getAllItems ' )
213
+ ->willReturn ([$ orderItem ]);
214
+
215
+ $ shipment = $ this ->createPartialMock (
216
+ Shipment::class,
217
+ ['addItem ' , 'setTotalQty ' , 'addTrack ' ]
218
+ );
219
+ $ shipment ->expects ($ this ->once ())
220
+ ->method ('addItem ' )
221
+ ->with ($ shipmentItem );
222
+ $ shipment ->expects ($ this ->once ())
223
+ ->method ('setTotalQty ' )
224
+ ->with (0.5 )
225
+ ->willReturn ($ shipment );
226
+
227
+ $ this ->converter ->expects ($ this ->any ())
228
+ ->method ('toShipment ' )
229
+ ->with ($ order )
230
+ ->willReturn ($ shipment );
231
+ $ this ->converter ->expects ($ this ->any ())
232
+ ->method ('itemToShipmentItem ' )
233
+ ->with ($ orderItem )
234
+ ->willReturn ($ shipmentItem );
235
+
236
+ if ($ tracks ) {
237
+ $ shipmentTrack = $ this ->createPartialMock (Track::class, ['addData ' ]);
238
+
239
+ if (empty ($ tracks [0 ]['number ' ])) {
240
+ $ shipmentTrack ->expects ($ this ->never ())
241
+ ->method ('addData ' );
242
+
243
+ $ this ->trackFactory ->expects ($ this ->never ())
244
+ ->method ('create ' );
245
+
246
+ $ shipment ->expects ($ this ->never ())
247
+ ->method ('addTrack ' );
248
+
249
+ $ this ->expectException (
250
+ LocalizedException::class
251
+ );
252
+ } else {
253
+ $ shipmentTrack ->expects ($ this ->once ())
254
+ ->method ('addData ' )
255
+ ->willReturnSelf ();
256
+
257
+ $ this ->trackFactory ->expects ($ this ->once ())
258
+ ->method ('create ' )
259
+ ->willReturn ($ shipmentTrack );
260
+
261
+ $ shipment ->expects ($ this ->once ())
262
+ ->method ('addTrack ' )
263
+ ->with ($ shipmentTrack );
264
+ }
265
+ }
266
+
267
+ $ this ->assertEquals ($ shipment , $ this ->subject ->create ($ order , ['1 ' => 0.5 ], $ tracks ));
268
+ }
269
+
174
270
/**
175
271
* @return array
176
272
*/
0 commit comments