7
7
namespace Magento \Quote \Test \Unit \Model ;
8
8
9
9
use Magento \Framework \Exception \NoSuchEntityException ;
10
-
11
10
use Magento \Quote \Model \CustomerManagement ;
11
+ use Magento \Sales \Api \Data \OrderAddressInterface ;
12
12
13
13
/**
14
14
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -540,12 +540,12 @@ public function testSubmit()
540
540
$ shippingAddress = $ this ->createMock (\Magento \Quote \Model \Quote \Address::class);
541
541
$ payment = $ this ->createMock (\Magento \Quote \Model \Quote \Payment::class);
542
542
$ 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 ' ] );
545
545
$ convertedPayment = $ this ->createMock (\Magento \Sales \Api \Data \OrderPaymentInterface::class);
546
546
$ convertedQuoteItem = $ this ->createMock (\Magento \Sales \Api \Data \OrderItemInterface::class);
547
547
548
- $ addresses = [$ convertedShippingAddress , $ convertedBillingAddress ];
548
+ $ addresses = [$ convertedShipping , $ convertedBilling ];
549
549
$ quoteItems = [$ quoteItem ];
550
550
$ convertedItems = [$ convertedQuoteItem ];
551
551
@@ -574,7 +574,7 @@ public function testSubmit()
574
574
575
575
]
576
576
)
577
- ->willReturn ($ convertedShippingAddress );
577
+ ->willReturn ($ convertedShipping );
578
578
$ this ->quoteAddressToOrderAddress ->expects ($ this ->at (1 ))
579
579
->method ('convert ' )
580
580
->with (
@@ -584,22 +584,27 @@ public function testSubmit()
584
584
585
585
]
586
586
)
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 );
588
591
$ this ->quoteItemToOrderItem ->expects ($ this ->once ())->method ('convert ' )
589
592
->with ($ quoteItem , ['parent_item ' => null ])
590
593
->willReturn ($ convertedQuoteItem );
591
594
$ this ->quotePaymentToOrderPayment ->expects ($ this ->once ())->method ('convert ' )->with ($ payment )
592
595
->willReturn ($ convertedPayment );
593
596
$ 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 );
594
599
595
600
$ order = $ this ->prepareOrderFactory (
596
601
$ baseOrder ,
597
- $ convertedBillingAddress ,
602
+ $ convertedBilling ,
598
603
$ addresses ,
599
604
$ convertedPayment ,
600
605
$ convertedItems ,
601
606
$ quoteId ,
602
- $ convertedShippingAddress
607
+ $ convertedShipping
603
608
);
604
609
605
610
$ this ->orderManagement ->expects ($ this ->once ())
@@ -973,9 +978,6 @@ protected function setPropertyValue(&$object, $property, $value)
973
978
return $ object ;
974
979
}
975
980
976
- /**
977
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
978
- */
979
981
public function testSubmitForCustomer ()
980
982
{
981
983
$ orderData = [];
@@ -988,16 +990,12 @@ public function testSubmitForCustomer()
988
990
$ shippingAddress = $ this ->createMock (\Magento \Quote \Model \Quote \Address::class);
989
991
$ payment = $ this ->createMock (\Magento \Quote \Model \Quote \Payment::class);
990
992
$ 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 ' ]);
997
995
$ convertedPayment = $ this ->createMock (\Magento \Sales \Api \Data \OrderPaymentInterface::class);
998
996
$ convertedQuoteItem = $ this ->createMock (\Magento \Sales \Api \Data \OrderItemInterface::class);
999
997
1000
- $ addresses = [$ convertedShippingAddress , $ convertedBillingAddress ];
998
+ $ addresses = [$ convertedShipping , $ convertedBilling ];
1001
999
$ quoteItems = [$ quoteItem ];
1002
1000
$ convertedItems = [$ convertedQuoteItem ];
1003
1001
@@ -1026,7 +1024,7 @@ public function testSubmitForCustomer()
1026
1024
1027
1025
]
1028
1026
)
1029
- ->willReturn ($ convertedShippingAddress );
1027
+ ->willReturn ($ convertedShipping );
1030
1028
$ this ->quoteAddressToOrderAddress ->expects ($ this ->at (1 ))
1031
1029
->method ('convert ' )
1032
1030
->with (
@@ -1036,22 +1034,24 @@ public function testSubmitForCustomer()
1036
1034
1037
1035
]
1038
1036
)
1039
- ->willReturn ($ convertedBillingAddress );
1037
+ ->willReturn ($ convertedBilling );
1040
1038
$ this ->quoteItemToOrderItem ->expects ($ this ->once ())->method ('convert ' )
1041
1039
->with ($ quoteItem , ['parent_item ' => null ])
1042
1040
->willReturn ($ convertedQuoteItem );
1043
1041
$ this ->quotePaymentToOrderPayment ->expects ($ this ->once ())->method ('convert ' )->with ($ payment )
1044
1042
->willReturn ($ convertedPayment );
1045
1043
$ 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 );
1046
1046
1047
1047
$ order = $ this ->prepareOrderFactory (
1048
1048
$ baseOrder ,
1049
- $ convertedBillingAddress ,
1049
+ $ convertedBilling ,
1050
1050
$ addresses ,
1051
1051
$ convertedPayment ,
1052
1052
$ convertedItems ,
1053
1053
$ quoteId ,
1054
- $ convertedShippingAddress
1054
+ $ convertedShipping
1055
1055
);
1056
1056
$ customerAddressMock = $ this ->getMockBuilder (\Magento \Customer \Api \Data \AddressInterface::class)
1057
1057
->getMockForAbstractClass ();
@@ -1060,6 +1060,8 @@ public function testSubmitForCustomer()
1060
1060
$ quote ->expects ($ this ->any ())->method ('addCustomerAddress ' )->with ($ customerAddressMock );
1061
1061
$ billingAddress ->expects ($ this ->once ())->method ('getCustomerId ' )->willReturn (2 );
1062
1062
$ 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 );
1063
1065
$ this ->orderManagement ->expects ($ this ->once ())
1064
1066
->method ('place ' )
1065
1067
->with ($ order )
@@ -1073,4 +1075,25 @@ public function testSubmitForCustomer()
1073
1075
$ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quote );
1074
1076
$ this ->assertEquals ($ order , $ this ->model ->submit ($ quote , $ orderData ));
1075
1077
}
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
+ }
1076
1099
}
0 commit comments