@@ -343,30 +343,38 @@ public function testExpire(): void
343
343
*/
344
344
public function testConvertCustomerCartToGuest (): void
345
345
{
346
- $ quoteId = 1 ;
347
346
$ addressArgs = ['customerAddressId ' => null ];
348
347
$ 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
+
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 );
355
357
$ this ->quoteMock ->expects ($ this ->once ())
356
- ->method ('setIsActive ' )->with (true )->willReturn ($ this ->quoteMock );
358
+ ->method ('setCustomerId ' )
359
+ ->with (null )
360
+ ->willReturn ($ this ->quoteMock );
357
361
$ this ->quoteMock ->expects ($ this ->once ())
358
- ->method ('setCustomerId ' )->with (null )->willReturn ($ this ->quoteMock );
362
+ ->method ('setCustomerEmail ' )->with ($ email )
363
+ ->willReturn ($ this ->quoteMock );
359
364
$ this ->quoteMock ->expects ($ this ->once ())
360
- ->method ('setCustomerEmail ' )->with (null )->willReturn ($ this ->quoteMock );
365
+ ->method ('setCustomerFirstname ' )
366
+ ->with ($ firstname )
367
+ ->willReturn ($ this ->quoteMock );
361
368
$ this ->quoteMock ->expects ($ this ->once ())
362
- ->method ('setCustomerFirstname ' )->with (null )->willReturn ($ this ->quoteMock );
369
+ ->method ('setCustomerLastname ' )->with ($ lastname )
370
+ ->willReturn ($ this ->quoteMock );
363
371
$ 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 )
366
374
->willReturn ($ this ->quoteMock );
367
375
$ this ->quoteMock ->expects ($ this ->once ())
368
376
->method ('setIsPersistent ' )->with (false )->willReturn ($ this ->quoteMock );
369
- $ this ->quoteMock ->expects ($ this ->exactly (3 ))
377
+ $ this ->quoteMock ->expects ($ this ->exactly (2 ))
370
378
->method ('getAddressesCollection ' )->willReturn ($ this ->abstractCollectionMock );
371
379
$ customerMock = $ this ->createMock (CustomerInterface::class);
372
380
$ customerMock ->expects ($ this ->once ())
@@ -375,49 +383,18 @@ public function testConvertCustomerCartToGuest(): void
375
383
->willReturnSelf ();
376
384
$ this ->quoteMock ->expects ($ this ->once ())
377
385
->method ('getCustomer ' )->willReturn ($ customerMock );
378
- $ this ->abstractCollectionMock ->expects ($ this ->exactly (3 ))->method ('walk ' )->with (
386
+ $ this ->abstractCollectionMock ->expects ($ this ->exactly (2 ))->method ('walk ' )->with (
379
387
$ this ->logicalOr (
380
388
$ this ->equalTo ('setCustomerAddressId ' ),
381
389
$ this ->equalTo ($ addressArgs ),
382
390
$ this ->equalTo ('setCustomerId ' ),
383
- $ this ->equalTo ($ customerIdArgs ),
384
- $ this ->equalTo ('setEmail ' ),
385
- $ this ->equalTo ($ emailArgs )
391
+ $ this ->equalTo ($ customerIdArgs )
386
392
)
387
393
);
388
394
$ 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 );
393
395
$ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ this ->quoteMock );
394
396
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 );
421
398
}
422
399
423
400
/**
@@ -429,7 +406,7 @@ private function getExtensionAttributesMock(): MockObject
429
406
{
430
407
$ extensionMockBuilder = $ this ->getMockBuilder (CartExtensionInterface::class);
431
408
try {
432
- $ extensionMockBuilder ->addMethods (['setShippingAssignments ' ]);
409
+ $ extensionMockBuilder ->onlyMethods (['setShippingAssignments ' ]);
433
410
} catch (RuntimeException $ e ) {
434
411
// do nothing as CartExtensionInterface already generated and has 'setShippingAssignments' method.
435
412
}
0 commit comments