22
22
use Magento \Sales \Model \Order \Shipping ;
23
23
use Magento \Sales \Model \Order \ShippingAssignment ;
24
24
use Magento \Sales \Model \Order \ShippingAssignmentBuilder ;
25
+ use Magento \Sales \Api \Data \OrderAddressInterface ;
25
26
use Magento \Sales \Model \OrderRepository ;
26
27
use Magento \Sales \Model \ResourceModel \Metadata ;
27
28
use Magento \Sales \Model \ResourceModel \Order as OrderResource ;
@@ -77,6 +78,11 @@ class OrderRepositoryTest extends TestCase
77
78
*/
78
79
private $ orderExtensionFactoryMock ;
79
80
81
+ /**
82
+ * @var ShippingAssignmentBuilder|MockObject
83
+ */
84
+ private $ shippingAssignmentBuilder ;
85
+
80
86
/**
81
87
* Setup the test
82
88
*
@@ -104,6 +110,9 @@ protected function setUp(): void
104
110
$ this ->paymentAdditionalInfoFactory = $ this ->getMockBuilder (PaymentAdditionalInfoInterfaceFactory::class)
105
111
->disableOriginalConstructor ()
106
112
->setMethods (['create ' ])->getMockForAbstractClass ();
113
+ $ this ->shippingAssignmentBuilder = $ this ->getMockBuilder (ShippingAssignmentBuilder::class)
114
+ ->disableOriginalConstructor ()
115
+ ->getMock ();
107
116
$ this ->orderRepository = $ this ->objectManager ->getObject (
108
117
OrderRepository::class,
109
118
[
@@ -113,6 +122,7 @@ protected function setUp(): void
113
122
'orderExtensionFactory ' => $ this ->orderExtensionFactoryMock ,
114
123
'orderTaxManagement ' => $ this ->orderTaxManagementMock ,
115
124
'paymentAdditionalInfoFactory ' => $ this ->paymentAdditionalInfoFactory ,
125
+ 'shippingAssignmentBuilder ' => $ this ->shippingAssignmentBuilder
116
126
]
117
127
);
118
128
}
@@ -194,7 +204,10 @@ public function testSave()
194
204
->method ('getShippingAssignments ' )
195
205
->willReturn ([$ shippingAssignment ]);
196
206
$ shippingAssignment ->expects ($ this ->once ())->method ('getShipping ' )->willReturn ($ shippingMock );
197
- $ shippingMock ->expects ($ this ->once ())->method ('getAddress ' );
207
+ $ shippingAddressMock = $ this ->getMockBuilder (OrderAddressInterface::class)
208
+ ->disableOriginalConstructor ()
209
+ ->getMock ();
210
+ $ shippingMock ->expects ($ this ->once ())->method ('getAddress ' )->willReturn ($ shippingAddressMock );
198
211
$ shippingMock ->expects ($ this ->once ())->method ('getMethod ' );
199
212
$ this ->metadata ->expects ($ this ->once ())->method ('getMapper ' )->willReturn ($ mapperMock );
200
213
$ mapperMock ->expects ($ this ->once ())->method ('save ' );
@@ -219,7 +232,7 @@ public function testGet()
219
232
->disableOriginalConstructor ()->getMockForAbstractClass ();
220
233
$ paymentMock ->expects ($ this ->once ())->method ('getAdditionalInformation ' )->willReturn ($ paymentInfo );
221
234
$ orderExtension = $ this ->getOrderExtensionMock ();
222
- $ orderExtension ->expects ($ this ->once ())->method ('getShippingAssignments ' )->willReturn (true );
235
+ $ orderExtension ->expects ($ this ->once ())->method ('getShippingAssignments ' )->willReturn (null );
223
236
$ orderExtension ->expects ($ this ->once ())->method ('setAppliedTaxes ' )->with ($ appliedTaxes );
224
237
$ orderExtension ->expects ($ this ->once ())->method ('setConvertingFromQuote ' )->with (true );
225
238
$ orderExtension ->expects ($ this ->once ())->method ('setItemAppliedTaxes ' )->with ($ items );
@@ -228,7 +241,7 @@ public function testGet()
228
241
$ orderEntity ->expects ($ this ->once ())->method ('load ' )->with ($ orderId )->willReturn ($ orderEntity );
229
242
$ orderEntity ->expects ($ this ->exactly (2 ))->method ('getEntityId ' )->willReturn ($ orderId );
230
243
$ orderEntity ->expects ($ this ->once ())->method ('getPayment ' )->willReturn ($ paymentMock );
231
- $ orderEntity ->expects ($ this ->exactly (2 ))->method ('setExtensionAttributes ' )->with ($ orderExtension );
244
+ $ orderEntity ->expects ($ this ->exactly (3 ))->method ('setExtensionAttributes ' )->with ($ orderExtension );
232
245
$ orderEntity ->expects ($ this ->exactly (3 ))
233
246
->method ('getExtensionAttributes ' )
234
247
->willReturnOnConsecutiveCalls (null , $ orderExtension , $ orderExtension );
@@ -240,6 +253,7 @@ public function testGet()
240
253
$ orderTaxDetailsMock ->expects ($ this ->once ())->method ('getItems ' )->willReturn ($ items );
241
254
$ this ->orderTaxManagementMock ->expects ($ this ->atLeastOnce ())->method ('getOrderTaxDetails ' )
242
255
->willReturn ($ orderTaxDetailsMock );
256
+ $ this ->shippingAssignmentBuilder ->expects ($ this ->once ())->method ('setOrder ' )->with ($ orderEntity );
243
257
244
258
$ this ->orderRepository ->get ($ orderId );
245
259
}
@@ -254,7 +268,7 @@ private function getOrderExtensionMock(): MockObject
254
268
$ mockBuilder = $ this ->getMockBuilder (OrderExtensionInterface::class)->disableOriginalConstructor ();
255
269
try {
256
270
$ mockBuilder
257
- ->addMethods (
271
+ ->onlyMethods (
258
272
[
259
273
'getShippingAssignments ' ,
260
274
'setAppliedTaxes ' ,
0 commit comments