@@ -343,30 +343,38 @@ public function testExpire(): void
343343 */
344344 public function testConvertCustomerCartToGuest (): void
345345 {
346- $ quoteId = 1 ;
347346 $ addressArgs = ['customerAddressId ' => null ];
348347 $ customerIdArgs = ['customerId ' => null ];
349- $ emailArgs = ['email ' => null ];
350-
351- $ this ->checkoutSessionMock ->expects ($ this ->once ())
352- ->method ('getQuoteId ' )->willReturn ($ quoteId );
353- $ this ->quoteMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ quoteId );
354- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('get ' )->with ($ quoteId )->willReturn ($ this ->quoteMock );
348+ $ email = 'test@example.com ' ;
349+ $ firstname = 'Firstname ' ;
350+ $ lastname = 'Lastname ' ;
351+
352+ $ billingAddressMock = $ this ->createMock (Address::class);
353+ $ billingAddressMock ->method ('getEmail ' )->willReturn ($ email );
354+ $ billingAddressMock ->method ('getFirstname ' )->willReturn ($ firstname );
355+ $ billingAddressMock ->method ('getLastname ' )->willReturn ($ lastname );
356+ $ this ->quoteMock ->method ('getBillingAddress ' )->willReturn ($ billingAddressMock );
355357 $ this ->quoteMock ->expects ($ this ->once ())
356- ->method ('setIsActive ' )->with (true )->willReturn ($ this ->quoteMock );
358+ ->method ('setCustomerId ' )
359+ ->with (null )
360+ ->willReturn ($ this ->quoteMock );
357361 $ this ->quoteMock ->expects ($ this ->once ())
358- ->method ('setCustomerId ' )->with (null )->willReturn ($ this ->quoteMock );
362+ ->method ('setCustomerEmail ' )->with ($ email )
363+ ->willReturn ($ this ->quoteMock );
359364 $ this ->quoteMock ->expects ($ this ->once ())
360- ->method ('setCustomerEmail ' )->with (null )->willReturn ($ this ->quoteMock );
365+ ->method ('setCustomerFirstname ' )
366+ ->with ($ firstname )
367+ ->willReturn ($ this ->quoteMock );
361368 $ this ->quoteMock ->expects ($ this ->once ())
362- ->method ('setCustomerFirstname ' )->with (null )->willReturn ($ this ->quoteMock );
369+ ->method ('setCustomerLastname ' )->with ($ lastname )
370+ ->willReturn ($ this ->quoteMock );
363371 $ this ->quoteMock ->expects ($ this ->once ())
364- ->method ('setCustomerLastname ' )-> with ( null )-> willReturn ( $ this -> quoteMock );
365- $ this -> quoteMock -> expects ( $ this -> never ())-> method ( ' setCustomerGroupId ' )
372+ ->method ('setCustomerGroupId ' )
373+ -> with ( 0 )
366374 ->willReturn ($ this ->quoteMock );
367375 $ this ->quoteMock ->expects ($ this ->once ())
368376 ->method ('setIsPersistent ' )->with (false )->willReturn ($ this ->quoteMock );
369- $ this ->quoteMock ->expects ($ this ->exactly (3 ))
377+ $ this ->quoteMock ->expects ($ this ->exactly (2 ))
370378 ->method ('getAddressesCollection ' )->willReturn ($ this ->abstractCollectionMock );
371379 $ customerMock = $ this ->createMock (CustomerInterface::class);
372380 $ customerMock ->expects ($ this ->once ())
@@ -375,49 +383,18 @@ public function testConvertCustomerCartToGuest(): void
375383 ->willReturnSelf ();
376384 $ this ->quoteMock ->expects ($ this ->once ())
377385 ->method ('getCustomer ' )->willReturn ($ customerMock );
378- $ this ->abstractCollectionMock ->expects ($ this ->exactly (3 ))->method ('walk ' )->with (
386+ $ this ->abstractCollectionMock ->expects ($ this ->exactly (2 ))->method ('walk ' )->with (
379387 $ this ->logicalOr (
380388 $ this ->equalTo ('setCustomerAddressId ' ),
381389 $ this ->equalTo ($ addressArgs ),
382390 $ this ->equalTo ('setCustomerId ' ),
383- $ this ->equalTo ($ customerIdArgs ),
384- $ this ->equalTo ('setEmail ' ),
385- $ this ->equalTo ($ emailArgs )
391+ $ this ->equalTo ($ customerIdArgs )
386392 )
387393 );
388394 $ this ->quoteMock ->expects ($ this ->once ())->method ('collectTotals ' )->willReturn ($ this ->quoteMock );
389- $ this ->persistentSessionMock ->expects ($ this ->once ())
390- ->method ('getSession ' )->willReturn ($ this ->sessionMock );
391- $ this ->sessionMock ->expects ($ this ->once ())
392- ->method ('removePersistentCookie ' )->willReturn ($ this ->sessionMock );
393395 $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ this ->quoteMock );
394396
395- $ this ->model ->convertCustomerCartToGuest ();
396- }
397-
398- /**
399- * @return void
400- */
401- public function testConvertCustomerCartToGuestWithEmptyQuote (): void
402- {
403- $ this ->checkoutSessionMock ->expects ($ this ->once ())
404- ->method ('getQuoteId ' )->willReturn (null );
405- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('get ' )->with (null )->willReturn (null );
406- $ this ->model ->convertCustomerCartToGuest ();
407- }
408-
409- /**
410- * @return void
411- */
412- public function testConvertCustomerCartToGuestWithEmptyQuoteId (): void
413- {
414- $ this ->checkoutSessionMock ->expects ($ this ->once ())
415- ->method ('getQuoteId ' )->willReturn (1 );
416- $ quoteWithNoId = $ this ->quoteMock = $ this ->createMock (Quote::class);
417- $ quoteWithNoId ->expects ($ this ->once ())->method ('getId ' )->willReturn (null );
418- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('get ' )->with (1 )->willReturn ($ quoteWithNoId );
419- $ this ->quoteMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
420- $ this ->model ->convertCustomerCartToGuest ();
397+ $ this ->model ->convertCustomerCartToGuest ($ this ->quoteMock );
421398 }
422399
423400 /**
@@ -429,7 +406,7 @@ private function getExtensionAttributesMock(): MockObject
429406 {
430407 $ extensionMockBuilder = $ this ->getMockBuilder (CartExtensionInterface::class);
431408 try {
432- $ extensionMockBuilder ->addMethods (['setShippingAssignments ' ]);
409+ $ extensionMockBuilder ->onlyMethods (['setShippingAssignments ' ]);
433410 } catch (RuntimeException $ e ) {
434411 // do nothing as CartExtensionInterface already generated and has 'setShippingAssignments' method.
435412 }
0 commit comments