@@ -240,7 +240,16 @@ protected function setUp(): void
240
240
);
241
241
242
242
$ this ->quoteMock = $ this ->getMockBuilder (Quote::class)
243
- ->addMethods (['setCustomerEmail ' , 'setCustomerGroupId ' , 'setCustomerId ' , 'setRemoteIp ' , 'setXForwardedFor ' ])
243
+ ->addMethods (
244
+ [
245
+ 'setCustomerEmail ' ,
246
+ 'setCustomerGroupId ' ,
247
+ 'setCustomerId ' ,
248
+ 'setRemoteIp ' ,
249
+ 'setXForwardedFor ' ,
250
+ 'getCustomerEmail '
251
+ ]
252
+ )
244
253
->onlyMethods (
245
254
[
246
255
'assignCustomer ' ,
@@ -821,9 +830,10 @@ public function testSubmit(): void
821
830
}
822
831
823
832
/**
833
+ * @dataProvider guestPlaceOrderDataProvider
824
834
* @return void
825
835
*/
826
- public function testPlaceOrderIfCustomerIsGuest (): void
836
+ public function testPlaceOrderIfCustomerIsGuest (? string $ settledEmail , int $ countSetAddress ): void
827
837
{
828
838
$ cartId = 100 ;
829
839
$ orderId = 332 ;
@@ -845,11 +855,17 @@ public function testPlaceOrderIfCustomerIsGuest(): void
845
855
$ this ->quoteMock ->expects ($ this ->once ())
846
856
->method ('getCustomer ' )
847
857
->willReturn ($ customerMock );
858
+ $ this ->quoteMock ->expects ($ this ->once ())
859
+ ->method ('getCustomerEmail ' )
860
+ ->willReturn ($ settledEmail );
848
861
$ this ->quoteMock ->expects ($ this ->once ())->method ('setCustomerId ' )->with (null )->willReturnSelf ();
849
- $ this ->quoteMock ->expects ($ this ->once ())->method ('setCustomerEmail ' )->with ($ email )->willReturnSelf ();
862
+ $ this ->quoteMock ->expects ($ this ->exactly ($ countSetAddress ))
863
+ ->method ('setCustomerEmail ' )
864
+ ->with ($ email )
865
+ ->willReturnSelf ();
850
866
851
867
$ addressMock = $ this ->createPartialMock (Address::class, ['getEmail ' ]);
852
- $ addressMock ->expects ($ this ->once ( ))->method ('getEmail ' )->willReturn ($ email );
868
+ $ addressMock ->expects ($ this ->exactly ( $ countSetAddress ))->method ('getEmail ' )->willReturn ($ email );
853
869
$ this ->quoteMock ->expects ($ this ->any ())->method ('getBillingAddress ' )->with ()->willReturn ($ addressMock );
854
870
855
871
$ this ->quoteMock ->expects ($ this ->once ())->method ('setCustomerIsGuest ' )->with (true )->willReturnSelf ();
@@ -912,6 +928,17 @@ public function testPlaceOrderIfCustomerIsGuest(): void
912
928
$ this ->assertEquals ($ orderId , $ service ->placeOrder ($ cartId ));
913
929
}
914
930
931
+ /**
932
+ * @return array
933
+ */
934
+ public function guestPlaceOrderDataProvider (): array
935
+ {
936
+ return [
937
+ [null , 1 ],
938
+ ['test@example.com ' , 0 ],
939
+ ];
940
+ }
941
+
915
942
/**
916
943
* @return void
917
944
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
0 commit comments