99namespace Magento \Persistent \Test \Unit \Model ;
1010
1111use Magento \Checkout \Model \Session ;
12+ use Magento \Customer \Api \Data \CustomerInterface ;
13+ use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
1214use Magento \Customer \Model \GroupManagement ;
1315use Magento \Eav \Model \Entity \Collection \AbstractCollection ;
1416use Magento \Persistent \Helper \Data ;
@@ -78,6 +80,11 @@ class QuoteManagerTest extends TestCase
7880 */
7981 private $ shippingAssignmentProcessor ;
8082
83+ /**
84+ * @var CustomerInterfaceFactory|MockObject
85+ */
86+ private $ customerDataFactory ;
87+
8188 protected function setUp (): void
8289 {
8390 $ this ->persistentSessionMock = $ this ->createMock (\Magento \Persistent \Helper \Session::class);
@@ -124,21 +131,24 @@ protected function setUp(): void
124131 'getItemsQty ' ,
125132 'getExtensionAttributes ' ,
126133 'setExtensionAttributes ' ,
127- '__wakeup '
134+ '__wakeup ' ,
135+ 'setCustomer '
128136 ])
129137 ->disableOriginalConstructor ()
130138 ->getMock ();
131139
132140 $ this ->cartExtensionFactory = $ this ->createPartialMock (CartExtensionFactory::class, ['create ' ]);
133141 $ this ->shippingAssignmentProcessor = $ this ->createPartialMock (ShippingAssignmentProcessor::class, ['create ' ]);
142+ $ this ->customerDataFactory = $ this ->createMock (CustomerInterfaceFactory::class);
134143
135144 $ this ->model = new QuoteManager (
136145 $ this ->persistentSessionMock ,
137146 $ this ->persistentDataMock ,
138147 $ this ->checkoutSessionMock ,
139148 $ this ->quoteRepositoryMock ,
140149 $ this ->cartExtensionFactory ,
141- $ this ->shippingAssignmentProcessor
150+ $ this ->shippingAssignmentProcessor ,
151+ $ this ->customerDataFactory
142152 );
143153 }
144154
@@ -189,6 +199,7 @@ public function testSetGuestWhenShoppingCartAndQuoteAreNotPersistent()
189199
190200 public function testSetGuest ()
191201 {
202+ $ customerId = 22 ;
192203 $ this ->checkoutSessionMock ->expects ($ this ->once ())
193204 ->method ('getQuote ' )->willReturn ($ this ->quoteMock );
194205 $ this ->quoteMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (11 );
@@ -220,6 +231,7 @@ public function testSetGuest()
220231 ->method ('getShippingAddress ' )->willReturn ($ quoteAddressMock );
221232 $ this ->quoteMock ->expects ($ this ->once ())
222233 ->method ('getBillingAddress ' )->willReturn ($ quoteAddressMock );
234+ $ this ->quoteMock ->method ('getCustomerId ' )->willReturn ($ customerId );
223235 $ this ->quoteMock ->expects ($ this ->once ())->method ('collectTotals ' )->willReturn ($ this ->quoteMock );
224236 $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ this ->quoteMock );
225237 $ this ->persistentSessionMock ->expects ($ this ->once ())
@@ -229,7 +241,6 @@ public function testSetGuest()
229241 $ this ->quoteMock ->expects ($ this ->once ())->method ('isVirtual ' )->willReturn (false );
230242 $ this ->quoteMock ->expects ($ this ->once ())->method ('getItemsQty ' )->willReturn (1 );
231243 $ extensionAttributes = $ this ->getMockBuilder (CartExtensionInterface::class)
232- ->addMethods (['getShippingAssignments ' , 'setShippingAssignments ' ])
233244 ->getMockForAbstractClass ();
234245 $ shippingAssignment = $ this ->createMock (ShippingAssignmentInterface::class);
235246 $ extensionAttributes ->expects ($ this ->once ())
@@ -248,6 +259,11 @@ public function testSetGuest()
248259 $ this ->quoteMock ->expects ($ this ->once ())
249260 ->method ('setExtensionAttributes ' )
250261 ->with ($ extensionAttributes );
262+ $ customerMock = $ this ->createMock (CustomerInterface::class);
263+ $ this ->customerDataFactory ->method ('create ' )->willReturn ($ customerMock );
264+ $ this ->quoteMock ->expects ($ this ->once ())
265+ ->method ('setCustomer ' )
266+ ->with ($ customerMock );
251267 $ this ->model ->setGuest (false );
252268 }
253269
0 commit comments