18
18
use Magento \Sales \Api \Data \OrderInterface ;
19
19
use Magento \Sales \Api \Data \OrderPaymentInterface ;
20
20
use Magento \Sales \Api \Data \OrderSearchResultInterfaceFactory as SearchResultFactory ;
21
+ use Magento \Sales \Model \Order ;
21
22
use Magento \Sales \Model \Order \Shipping ;
22
23
use Magento \Sales \Model \Order \ShippingAssignment ;
23
24
use Magento \Sales \Model \Order \ShippingAssignmentBuilder ;
24
25
use Magento \Sales \Model \OrderRepository ;
25
26
use Magento \Sales \Model \ResourceModel \Metadata ;
26
- use Magento \Sales \Model \ResourceModel \Order ;
27
+ use Magento \Sales \Model \ResourceModel \Order as OrderResource ;
27
28
use Magento \Sales \Model \ResourceModel \Order \Collection ;
28
29
use Magento \Tax \Api \Data \OrderTaxDetailsInterface ;
29
30
use Magento \Tax \Api \OrderTaxManagementInterface ;
@@ -70,6 +71,11 @@ class OrderRepositoryTest extends TestCase
70
71
*/
71
72
private $ paymentAdditionalInfoFactory ;
72
73
74
+ /**
75
+ * @var OrderExtensionFactory|\PHPUnit_Framework_MockObject_MockObject
76
+ */
77
+ private $ orderExtensionFactoryMock ;
78
+
73
79
/**
74
80
* Setup the test
75
81
*
@@ -88,7 +94,7 @@ protected function setUp(): void
88
94
$ this ->collectionProcessor = $ this ->createMock (
89
95
CollectionProcessorInterface::class
90
96
);
91
- $ orderExtensionFactoryMock = $ this ->getMockBuilder (OrderExtensionFactory::class)
97
+ $ this -> orderExtensionFactoryMock = $ this ->getMockBuilder (OrderExtensionFactory::class)
92
98
->disableOriginalConstructor ()
93
99
->getMock ();
94
100
$ this ->orderTaxManagementMock = $ this ->getMockBuilder (OrderTaxManagementInterface::class)
@@ -103,7 +109,7 @@ protected function setUp(): void
103
109
'metadata ' => $ this ->metadata ,
104
110
'searchResultFactory ' => $ this ->searchResultFactory ,
105
111
'collectionProcessor ' => $ this ->collectionProcessor ,
106
- 'orderExtensionFactory ' => $ orderExtensionFactoryMock ,
112
+ 'orderExtensionFactory ' => $ this -> orderExtensionFactoryMock ,
107
113
'orderTaxManagement ' => $ this ->orderTaxManagementMock ,
108
114
'paymentAdditionalInfoFactory ' => $ this ->paymentAdditionalInfoFactory
109
115
]
@@ -178,10 +184,10 @@ public function testGetList()
178
184
*/
179
185
public function testSave ()
180
186
{
181
- $ mapperMock = $ this ->getMockBuilder (Order ::class)
187
+ $ mapperMock = $ this ->getMockBuilder (OrderResource ::class)
182
188
->disableOriginalConstructor ()
183
189
->getMock ();
184
- $ orderEntity = $ this ->createMock (\ Magento \ Sales \ Model \ Order::class);
190
+ $ orderEntity = $ this ->createMock (Order::class);
185
191
$ extensionAttributes = $ this ->getMockBuilder (OrderExtension::class)
186
192
->addMethods (['getShippingAssignments ' ])
187
193
->getMock ();
@@ -207,4 +213,57 @@ public function testSave()
207
213
$ orderEntity ->expects ($ this ->any ())->method ('getEntityId ' )->willReturn (1 );
208
214
$ this ->orderRepository ->save ($ orderEntity );
209
215
}
216
+
217
+ /**
218
+ * Test for method get.
219
+ *
220
+ * @return void
221
+ */
222
+ public function testGet ()
223
+ {
224
+ $ orderId = 1 ;
225
+ $ appliedTaxes = 'applied_taxes ' ;
226
+ $ items = 'items ' ;
227
+ $ paymentInfo = [];
228
+
229
+ $ orderEntity = $ this ->createMock (Order::class);
230
+ $ paymentMock = $ this ->getMockBuilder (OrderPaymentInterface::class)
231
+ ->disableOriginalConstructor ()->getMockForAbstractClass ();
232
+ $ paymentMock ->expects ($ this ->once ())->method ('getAdditionalInformation ' )->willReturn ($ paymentInfo );
233
+ $ orderExtension = $ this ->getMockBuilder (OrderExtension::class)
234
+ ->setMethods (
235
+ [
236
+ 'getShippingAssignments ' ,
237
+ 'setAppliedTaxes ' ,
238
+ 'setConvertingFromQuote ' ,
239
+ 'setItemAppliedTaxes ' ,
240
+ 'setPaymentAdditionalInfo '
241
+ ]
242
+ )
243
+ ->disableOriginalConstructor ()
244
+ ->getMockForAbstractClass ();
245
+ $ orderExtension ->expects ($ this ->once ())->method ('getShippingAssignments ' )->willReturn (true );
246
+ $ orderExtension ->expects ($ this ->once ())->method ('setAppliedTaxes ' )->with ($ appliedTaxes );
247
+ $ orderExtension ->expects ($ this ->once ())->method ('setConvertingFromQuote ' )->with (true );
248
+ $ orderExtension ->expects ($ this ->once ())->method ('setItemAppliedTaxes ' )->with ($ items );
249
+ $ orderExtension ->expects ($ this ->once ())->method ('setPaymentAdditionalInfo ' )->with ($ paymentInfo );
250
+ $ this ->orderExtensionFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ orderExtension );
251
+ $ orderEntity ->expects ($ this ->once ())->method ('load ' )->with ($ orderId )->willReturn ($ orderEntity );
252
+ $ orderEntity ->expects ($ this ->exactly (2 ))->method ('getEntityId ' )->willReturn ($ orderId );
253
+ $ orderEntity ->expects ($ this ->once ())->method ('getPayment ' )->willReturn ($ paymentMock );
254
+ $ orderEntity ->expects ($ this ->exactly (2 ))->method ('setExtensionAttributes ' )->with ($ orderExtension );
255
+ $ orderEntity ->expects ($ this ->exactly (3 ))
256
+ ->method ('getExtensionAttributes ' )
257
+ ->willReturnOnConsecutiveCalls (null , $ orderExtension , $ orderExtension );
258
+ $ this ->metadata ->expects ($ this ->once ())->method ('getNewInstance ' )->willReturn ($ orderEntity );
259
+ $ orderTaxDetailsMock = $ this ->getMockBuilder (OrderTaxDetailsInterface::class)
260
+ ->disableOriginalConstructor ()
261
+ ->setMethods (['setAppliedTaxes ' ])->getMockForAbstractClass ();
262
+ $ orderTaxDetailsMock ->expects ($ this ->once ())->method ('getAppliedTaxes ' )->willReturn ($ appliedTaxes );
263
+ $ orderTaxDetailsMock ->expects ($ this ->once ())->method ('getItems ' )->willReturn ($ items );
264
+ $ this ->orderTaxManagementMock ->expects ($ this ->atLeastOnce ())->method ('getOrderTaxDetails ' )
265
+ ->willReturn ($ orderTaxDetailsMock );
266
+
267
+ $ this ->orderRepository ->get ($ orderId );
268
+ }
210
269
}
0 commit comments