77namespace Magento \Quote \Test \Unit \Model ;
88
99use Magento \Framework \Exception \NoSuchEntityException ;
10-
1110use Magento \Quote \Model \CustomerManagement ;
11+ use Magento \Sales \Api \Data \OrderAddressInterface ;
1212
1313/**
1414 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -540,12 +540,12 @@ public function testSubmit()
540540 $ shippingAddress = $ this ->createMock (\Magento \Quote \Model \Quote \Address::class);
541541 $ payment = $ this ->createMock (\Magento \Quote \Model \Quote \Payment::class);
542542 $ baseOrder = $ this ->createMock (\Magento \Sales \Api \Data \OrderInterface::class);
543- $ convertedBillingAddress = $ this ->createMock (\ Magento \ Sales \ Api \ Data \ OrderAddressInterface::class);
544- $ convertedShippingAddress = $ this ->createMock (\ Magento \ Sales \ Api \ Data \ OrderAddressInterface::class);
543+ $ convertedBilling = $ this ->createPartialMockForAbstractClass ( OrderAddressInterface::class, [ ' setData ' ] );
544+ $ convertedShipping = $ this ->createPartialMockForAbstractClass ( OrderAddressInterface::class, [ ' setData ' ] );
545545 $ convertedPayment = $ this ->createMock (\Magento \Sales \Api \Data \OrderPaymentInterface::class);
546546 $ convertedQuoteItem = $ this ->createMock (\Magento \Sales \Api \Data \OrderItemInterface::class);
547547
548- $ addresses = [$ convertedShippingAddress , $ convertedBillingAddress ];
548+ $ addresses = [$ convertedShipping , $ convertedBilling ];
549549 $ quoteItems = [$ quoteItem ];
550550 $ convertedItems = [$ convertedQuoteItem ];
551551
@@ -574,7 +574,7 @@ public function testSubmit()
574574575575 ]
576576 )
577- ->willReturn ($ convertedShippingAddress );
577+ ->willReturn ($ convertedShipping );
578578 $ this ->quoteAddressToOrderAddress ->expects ($ this ->at (1 ))
579579 ->method ('convert ' )
580580 ->with (
@@ -584,22 +584,27 @@ public function testSubmit()
584584585585 ]
586586 )
587- ->willReturn ($ convertedBillingAddress );
587+ ->willReturn ($ convertedBilling );
588+
589+ $ billingAddress ->expects ($ this ->once ())->method ('getId ' )->willReturn (4 );
590+ $ convertedBilling ->expects ($ this ->once ())->method ('setData ' )->with ('quote_address_id ' , 4 );
588591 $ this ->quoteItemToOrderItem ->expects ($ this ->once ())->method ('convert ' )
589592 ->with ($ quoteItem , ['parent_item ' => null ])
590593 ->willReturn ($ convertedQuoteItem );
591594 $ this ->quotePaymentToOrderPayment ->expects ($ this ->once ())->method ('convert ' )->with ($ payment )
592595 ->willReturn ($ convertedPayment );
593596 $ shippingAddress ->expects ($ this ->once ())->method ('getShippingMethod ' )->willReturn ('free ' );
597+ $ shippingAddress ->expects ($ this ->once ())->method ('getId ' )->willReturn (5 );
598+ $ convertedShipping ->expects ($ this ->once ())->method ('setData ' )->with ('quote_address_id ' , 5 );
594599
595600 $ order = $ this ->prepareOrderFactory (
596601 $ baseOrder ,
597- $ convertedBillingAddress ,
602+ $ convertedBilling ,
598603 $ addresses ,
599604 $ convertedPayment ,
600605 $ convertedItems ,
601606 $ quoteId ,
602- $ convertedShippingAddress
607+ $ convertedShipping
603608 );
604609
605610 $ this ->orderManagement ->expects ($ this ->once ())
@@ -973,9 +978,6 @@ protected function setPropertyValue(&$object, $property, $value)
973978 return $ object ;
974979 }
975980
976- /**
977- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
978- */
979981 public function testSubmitForCustomer ()
980982 {
981983 $ orderData = [];
@@ -988,16 +990,12 @@ public function testSubmitForCustomer()
988990 $ shippingAddress = $ this ->createMock (\Magento \Quote \Model \Quote \Address::class);
989991 $ payment = $ this ->createMock (\Magento \Quote \Model \Quote \Payment::class);
990992 $ baseOrder = $ this ->createMock (\Magento \Sales \Api \Data \OrderInterface::class);
991- $ convertedBillingAddress = $ this ->createMock (
992- \Magento \Sales \Api \Data \OrderAddressInterface::class
993- );
994- $ convertedShippingAddress = $ this ->createMock (
995- \Magento \Sales \Api \Data \OrderAddressInterface::class
996- );
993+ $ convertedBilling = $ this ->createPartialMockForAbstractClass (OrderAddressInterface::class, ['setData ' ]);
994+ $ convertedShipping = $ this ->createPartialMockForAbstractClass (OrderAddressInterface::class, ['setData ' ]);
997995 $ convertedPayment = $ this ->createMock (\Magento \Sales \Api \Data \OrderPaymentInterface::class);
998996 $ convertedQuoteItem = $ this ->createMock (\Magento \Sales \Api \Data \OrderItemInterface::class);
999997
1000- $ addresses = [$ convertedShippingAddress , $ convertedBillingAddress ];
998+ $ addresses = [$ convertedShipping , $ convertedBilling ];
1001999 $ quoteItems = [$ quoteItem ];
10021000 $ convertedItems = [$ convertedQuoteItem ];
10031001
@@ -1026,7 +1024,7 @@ public function testSubmitForCustomer()
1026102410271025 ]
10281026 )
1029- ->willReturn ($ convertedShippingAddress );
1027+ ->willReturn ($ convertedShipping );
10301028 $ this ->quoteAddressToOrderAddress ->expects ($ this ->at (1 ))
10311029 ->method ('convert ' )
10321030 ->with (
@@ -1036,22 +1034,24 @@ public function testSubmitForCustomer()
1036103410371035 ]
10381036 )
1039- ->willReturn ($ convertedBillingAddress );
1037+ ->willReturn ($ convertedBilling );
10401038 $ this ->quoteItemToOrderItem ->expects ($ this ->once ())->method ('convert ' )
10411039 ->with ($ quoteItem , ['parent_item ' => null ])
10421040 ->willReturn ($ convertedQuoteItem );
10431041 $ this ->quotePaymentToOrderPayment ->expects ($ this ->once ())->method ('convert ' )->with ($ payment )
10441042 ->willReturn ($ convertedPayment );
10451043 $ shippingAddress ->expects ($ this ->once ())->method ('getShippingMethod ' )->willReturn ('free ' );
1044+ $ shippingAddress ->expects ($ this ->once ())->method ('getId ' )->willReturn (5 );
1045+ $ convertedShipping ->expects ($ this ->once ())->method ('setData ' )->with ('quote_address_id ' , 5 );
10461046
10471047 $ order = $ this ->prepareOrderFactory (
10481048 $ baseOrder ,
1049- $ convertedBillingAddress ,
1049+ $ convertedBilling ,
10501050 $ addresses ,
10511051 $ convertedPayment ,
10521052 $ convertedItems ,
10531053 $ quoteId ,
1054- $ convertedShippingAddress
1054+ $ convertedShipping
10551055 );
10561056 $ customerAddressMock = $ this ->getMockBuilder (\Magento \Customer \Api \Data \AddressInterface::class)
10571057 ->getMockForAbstractClass ();
@@ -1060,6 +1060,8 @@ public function testSubmitForCustomer()
10601060 $ quote ->expects ($ this ->any ())->method ('addCustomerAddress ' )->with ($ customerAddressMock );
10611061 $ billingAddress ->expects ($ this ->once ())->method ('getCustomerId ' )->willReturn (2 );
10621062 $ billingAddress ->expects ($ this ->once ())->method ('getSaveInAddressBook ' )->willReturn (false );
1063+ $ billingAddress ->expects ($ this ->once ())->method ('getId ' )->willReturn (4 );
1064+ $ convertedBilling ->expects ($ this ->once ())->method ('setData ' )->with ('quote_address_id ' , 4 );
10631065 $ this ->orderManagement ->expects ($ this ->once ())
10641066 ->method ('place ' )
10651067 ->with ($ order )
@@ -1073,4 +1075,25 @@ public function testSubmitForCustomer()
10731075 $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quote );
10741076 $ this ->assertEquals ($ order , $ this ->model ->submit ($ quote , $ orderData ));
10751077 }
1078+
1079+ /**
1080+ * Get mock for abstract class with methods.
1081+ *
1082+ * @param string $className
1083+ * @param array $methods
1084+ *
1085+ * @return \PHPUnit_Framework_MockObject_MockObject
1086+ */
1087+ private function createPartialMockForAbstractClass ($ className , $ methods = [])
1088+ {
1089+ return $ this ->getMockForAbstractClass (
1090+ $ className ,
1091+ [],
1092+ '' ,
1093+ true ,
1094+ true ,
1095+ true ,
1096+ $ methods
1097+ );
1098+ }
10761099}
0 commit comments