1818use Magento \Sales \Api \Data \OrderInterface ;
1919use Magento \Sales \Api \Data \OrderPaymentInterface ;
2020use Magento \Sales \Api \Data \OrderSearchResultInterfaceFactory as SearchResultFactory ;
21+ use Magento \Sales \Model \Order ;
2122use Magento \Sales \Model \Order \Shipping ;
2223use Magento \Sales \Model \Order \ShippingAssignment ;
2324use Magento \Sales \Model \Order \ShippingAssignmentBuilder ;
2425use Magento \Sales \Model \OrderRepository ;
2526use Magento \Sales \Model \ResourceModel \Metadata ;
26- use Magento \Sales \Model \ResourceModel \Order ;
27+ use Magento \Sales \Model \ResourceModel \Order as OrderResource ;
2728use Magento \Sales \Model \ResourceModel \Order \Collection ;
2829use Magento \Tax \Api \Data \OrderTaxDetailsInterface ;
2930use Magento \Tax \Api \OrderTaxManagementInterface ;
@@ -70,6 +71,11 @@ class OrderRepositoryTest extends TestCase
7071 */
7172 private $ paymentAdditionalInfoFactory ;
7273
74+ /**
75+ * @var OrderExtensionFactory|\MockObject
76+ */
77+ private $ orderExtensionFactoryMock ;
78+
7379 /**
7480 * Setup the test
7581 *
@@ -88,7 +94,7 @@ protected function setUp(): void
8894 $ this ->collectionProcessor = $ this ->createMock (
8995 CollectionProcessorInterface::class
9096 );
91- $ orderExtensionFactoryMock = $ this ->getMockBuilder (OrderExtensionFactory::class)
97+ $ this -> orderExtensionFactoryMock = $ this ->getMockBuilder (OrderExtensionFactory::class)
9298 ->disableOriginalConstructor ()
9399 ->getMock ();
94100 $ this ->orderTaxManagementMock = $ this ->getMockBuilder (OrderTaxManagementInterface::class)
@@ -103,7 +109,7 @@ protected function setUp(): void
103109 'metadata ' => $ this ->metadata ,
104110 'searchResultFactory ' => $ this ->searchResultFactory ,
105111 'collectionProcessor ' => $ this ->collectionProcessor ,
106- 'orderExtensionFactory ' => $ orderExtensionFactoryMock ,
112+ 'orderExtensionFactory ' => $ this -> orderExtensionFactoryMock ,
107113 'orderTaxManagement ' => $ this ->orderTaxManagementMock ,
108114 'paymentAdditionalInfoFactory ' => $ this ->paymentAdditionalInfoFactory
109115 ]
@@ -178,10 +184,10 @@ public function testGetList()
178184 */
179185 public function testSave ()
180186 {
181- $ mapperMock = $ this ->getMockBuilder (Order ::class)
187+ $ mapperMock = $ this ->getMockBuilder (OrderResource ::class)
182188 ->disableOriginalConstructor ()
183189 ->getMock ();
184- $ orderEntity = $ this ->createMock (\ Magento \ Sales \ Model \ Order::class);
190+ $ orderEntity = $ this ->createMock (Order::class);
185191 $ extensionAttributes = $ this ->getMockBuilder (OrderExtension::class)
186192 ->addMethods (['getShippingAssignments ' ])
187193 ->getMock ();
@@ -207,4 +213,57 @@ public function testSave()
207213 $ orderEntity ->expects ($ this ->any ())->method ('getEntityId ' )->willReturn (1 );
208214 $ this ->orderRepository ->save ($ orderEntity );
209215 }
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+ }
210269}
0 commit comments