9
9
use Magento \Framework \Exception \NoSuchEntityException ;
10
10
11
11
use Magento \Quote \Model \CustomerManagement ;
12
+ use Magento \Sales \Api \Data \OrderAddressInterface ;
12
13
13
14
/**
14
15
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -131,6 +132,11 @@ class QuoteManagementTest extends \PHPUnit\Framework\TestCase
131
132
*/
132
133
private $ addressRepositoryMock ;
133
134
135
+ /**
136
+ * @var \PHPUnit_Framework_MockObject_MockObject
137
+ */
138
+ private $ quoteFactoryMock ;
139
+
134
140
/**
135
141
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
136
142
*/
@@ -530,12 +536,12 @@ public function testSubmit()
530
536
$ shippingAddress = $ this ->createMock (\Magento \Quote \Model \Quote \Address::class);
531
537
$ payment = $ this ->createMock (\Magento \Quote \Model \Quote \Payment::class);
532
538
$ baseOrder = $ this ->createMock (\Magento \Sales \Api \Data \OrderInterface::class);
533
- $ convertedBillingAddress = $ this ->createMock (\ Magento \ Sales \ Api \ Data \ OrderAddressInterface::class);
534
- $ convertedShippingAddress = $ this ->createMock (\ Magento \ Sales \ Api \ Data \ OrderAddressInterface::class);
539
+ $ convertedBilling = $ this ->createPartialMockForAbstractClass ( OrderAddressInterface::class, [ ' setData ' ] );
540
+ $ convertedShipping = $ this ->createPartialMockForAbstractClass ( OrderAddressInterface::class, [ ' setData ' ] );
535
541
$ convertedPayment = $ this ->createMock (\Magento \Sales \Api \Data \OrderPaymentInterface::class);
536
542
$ convertedQuoteItem = $ this ->createMock (\Magento \Sales \Api \Data \OrderItemInterface::class);
537
543
538
- $ addresses = [$ convertedShippingAddress , $ convertedBillingAddress ];
544
+ $ addresses = [$ convertedShipping , $ convertedBilling ];
539
545
$ quoteItems = [$ quoteItem ];
540
546
$ convertedItems = [$ convertedQuoteItem ];
541
547
@@ -564,7 +570,7 @@ public function testSubmit()
564
570
565
571
]
566
572
)
567
- ->willReturn ($ convertedShippingAddress );
573
+ ->willReturn ($ convertedShipping );
568
574
$ this ->quoteAddressToOrderAddress ->expects ($ this ->at (1 ))
569
575
->method ('convert ' )
570
576
->with (
@@ -574,22 +580,26 @@ public function testSubmit()
574
580
575
581
]
576
582
)
577
- ->willReturn ($ convertedBillingAddress );
583
+ ->willReturn ($ convertedBilling );
584
+ $ billingAddress ->expects ($ this ->once ())->method ('getId ' )->willReturn (4 );
585
+ $ convertedBilling ->expects ($ this ->once ())->method ('setData ' )->with ('quote_address_id ' , 4 );
586
+
578
587
$ this ->quoteItemToOrderItem ->expects ($ this ->once ())->method ('convert ' )
579
588
->with ($ quoteItem , ['parent_item ' => null ])
580
589
->willReturn ($ convertedQuoteItem );
581
590
$ this ->quotePaymentToOrderPayment ->expects ($ this ->once ())->method ('convert ' )->with ($ payment )
582
591
->willReturn ($ convertedPayment );
583
592
$ shippingAddress ->expects ($ this ->once ())->method ('getShippingMethod ' )->willReturn ('free ' );
584
-
593
+ $ shippingAddress ->expects ($ this ->once ())->method ('getId ' )->willReturn (5 );
594
+ $ convertedShipping ->expects ($ this ->once ())->method ('setData ' )->with ('quote_address_id ' , 5 );
585
595
$ order = $ this ->prepareOrderFactory (
586
596
$ baseOrder ,
587
- $ convertedBillingAddress ,
597
+ $ convertedBilling ,
588
598
$ addresses ,
589
599
$ convertedPayment ,
590
600
$ convertedItems ,
591
601
$ quoteId ,
592
- $ convertedShippingAddress
602
+ $ convertedShipping
593
603
);
594
604
595
605
$ this ->orderManagement ->expects ($ this ->once ())
@@ -857,22 +867,22 @@ protected function getQuote(
857
867
858
868
/**
859
869
* @param \Magento\Sales\Api\Data\OrderInterface $baseOrder
860
- * @param \Magento\Sales\Api\Data\ OrderAddressInterface $billingAddress
870
+ * @param OrderAddressInterface $billingAddress
861
871
* @param array $addresses
862
872
* @param $payment
863
873
* @param array $items
864
874
* @param $quoteId
865
- * @param \Magento\Sales\Api\Data\ OrderAddressInterface $shippingAddress
875
+ * @param OrderAddressInterface $shippingAddress
866
876
* @return \PHPUnit_Framework_MockObject_MockObject
867
877
*/
868
878
protected function prepareOrderFactory (
869
879
\Magento \Sales \Api \Data \OrderInterface $ baseOrder ,
870
- \ Magento \ Sales \ Api \ Data \ OrderAddressInterface $ billingAddress ,
880
+ OrderAddressInterface $ billingAddress ,
871
881
array $ addresses ,
872
882
$ payment ,
873
883
array $ items ,
874
884
$ quoteId ,
875
- \ Magento \ Sales \ Api \ Data \ OrderAddressInterface $ shippingAddress = null ,
885
+ OrderAddressInterface $ shippingAddress = null ,
876
886
$ customerId = null
877
887
) {
878
888
$ order = $ this ->createPartialMock (
@@ -963,9 +973,6 @@ protected function setPropertyValue(&$object, $property, $value)
963
973
return $ object ;
964
974
}
965
975
966
- /**
967
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
968
- */
969
976
public function testSubmitForCustomer ()
970
977
{
971
978
$ orderData = [];
@@ -978,16 +985,12 @@ public function testSubmitForCustomer()
978
985
$ shippingAddress = $ this ->createMock (\Magento \Quote \Model \Quote \Address::class);
979
986
$ payment = $ this ->createMock (\Magento \Quote \Model \Quote \Payment::class);
980
987
$ baseOrder = $ this ->createMock (\Magento \Sales \Api \Data \OrderInterface::class);
981
- $ convertedBillingAddress = $ this ->createMock (
982
- \Magento \Sales \Api \Data \OrderAddressInterface::class
983
- );
984
- $ convertedShippingAddress = $ this ->createMock (
985
- \Magento \Sales \Api \Data \OrderAddressInterface::class
986
- );
988
+ $ convertedBilling = $ this ->createPartialMockForAbstractClass (OrderAddressInterface::class, ['setData ' ]);
989
+ $ convertedShipping = $ this ->createPartialMockForAbstractClass (OrderAddressInterface::class, ['setData ' ]);
987
990
$ convertedPayment = $ this ->createMock (\Magento \Sales \Api \Data \OrderPaymentInterface::class);
988
991
$ convertedQuoteItem = $ this ->createMock (\Magento \Sales \Api \Data \OrderItemInterface::class);
989
992
990
- $ addresses = [$ convertedShippingAddress , $ convertedBillingAddress ];
993
+ $ addresses = [$ convertedShipping , $ convertedBilling ];
991
994
$ quoteItems = [$ quoteItem ];
992
995
$ convertedItems = [$ convertedQuoteItem ];
993
996
@@ -1016,7 +1019,7 @@ public function testSubmitForCustomer()
1016
1019
1017
1020
]
1018
1021
)
1019
- ->willReturn ($ convertedShippingAddress );
1022
+ ->willReturn ($ convertedShipping );
1020
1023
$ this ->quoteAddressToOrderAddress ->expects ($ this ->at (1 ))
1021
1024
->method ('convert ' )
1022
1025
->with (
@@ -1026,22 +1029,23 @@ public function testSubmitForCustomer()
1026
1029
1027
1030
]
1028
1031
)
1029
- ->willReturn ($ convertedBillingAddress );
1032
+ ->willReturn ($ convertedBilling );
1030
1033
$ this ->quoteItemToOrderItem ->expects ($ this ->once ())->method ('convert ' )
1031
1034
->with ($ quoteItem , ['parent_item ' => null ])
1032
1035
->willReturn ($ convertedQuoteItem );
1033
1036
$ this ->quotePaymentToOrderPayment ->expects ($ this ->once ())->method ('convert ' )->with ($ payment )
1034
1037
->willReturn ($ convertedPayment );
1035
1038
$ shippingAddress ->expects ($ this ->once ())->method ('getShippingMethod ' )->willReturn ('free ' );
1036
-
1039
+ $ shippingAddress ->expects ($ this ->once ())->method ('getId ' )->willReturn (5 );
1040
+ $ convertedShipping ->expects ($ this ->once ())->method ('setData ' )->with ('quote_address_id ' , 5 );
1037
1041
$ order = $ this ->prepareOrderFactory (
1038
1042
$ baseOrder ,
1039
- $ convertedBillingAddress ,
1043
+ $ convertedBilling ,
1040
1044
$ addresses ,
1041
1045
$ convertedPayment ,
1042
1046
$ convertedItems ,
1043
1047
$ quoteId ,
1044
- $ convertedShippingAddress
1048
+ $ convertedShipping
1045
1049
);
1046
1050
$ customerAddressMock = $ this ->getMockBuilder (\Magento \Customer \Api \Data \AddressInterface::class)
1047
1051
->getMockForAbstractClass ();
@@ -1050,6 +1054,8 @@ public function testSubmitForCustomer()
1050
1054
$ quote ->expects ($ this ->any ())->method ('addCustomerAddress ' )->with ($ customerAddressMock );
1051
1055
$ billingAddress ->expects ($ this ->once ())->method ('getCustomerId ' )->willReturn (2 );
1052
1056
$ billingAddress ->expects ($ this ->once ())->method ('getSaveInAddressBook ' )->willReturn (false );
1057
+ $ billingAddress ->expects ($ this ->once ())->method ('getId ' )->willReturn (4 );
1058
+ $ convertedBilling ->expects ($ this ->once ())->method ('setData ' )->with ('quote_address_id ' , 4 );
1053
1059
$ this ->orderManagement ->expects ($ this ->once ())
1054
1060
->method ('place ' )
1055
1061
->with ($ order )
@@ -1063,4 +1069,25 @@ public function testSubmitForCustomer()
1063
1069
$ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quote );
1064
1070
$ this ->assertEquals ($ order , $ this ->model ->submit ($ quote , $ orderData ));
1065
1071
}
1072
+
1073
+ /**
1074
+ * Get mock for abstract class with methods.
1075
+ *
1076
+ * @param string $className
1077
+ * @param array $methods
1078
+ *
1079
+ * @return \PHPUnit_Framework_MockObject_MockObject
1080
+ */
1081
+ private function createPartialMockForAbstractClass ($ className , $ methods = [])
1082
+ {
1083
+ return $ this ->getMockForAbstractClass (
1084
+ $ className ,
1085
+ [],
1086
+ '' ,
1087
+ true ,
1088
+ true ,
1089
+ true ,
1090
+ $ methods
1091
+ );
1092
+ }
1066
1093
}
0 commit comments