11<?php
22/**
3- *
43 * Copyright © Magento, Inc. All rights reserved.
54 * See COPYING.txt for license details.
65 */
76declare (strict_types=1 );
87
98namespace Magento \Persistent \Test \Unit \Observer ;
109
10+ use Magento \Checkout \Model \Session as CheckoutSession ;
1111use Magento \Framework \Event ;
1212use Magento \Framework \Event \Observer ;
1313use Magento \Persistent \Controller \Index ;
1414use Magento \Persistent \Helper \Data ;
1515use Magento \Persistent \Helper \Session ;
16- use Magento \Persistent \Model \QuoteManager ;
1716use Magento \Persistent \Observer \MakePersistentQuoteGuestObserver ;
1817use PHPUnit \Framework \MockObject \MockObject ;
1918use PHPUnit \Framework \TestCase ;
@@ -48,10 +47,10 @@ class MakePersistentQuoteGuestObserverTest extends TestCase
4847 /**
4948 * @var MockObject
5049 */
51- protected $ quoteManagerMock ;
50+ protected $ checkoutSession ;
5251
5352 /**
54- * @var MockObject
53+ * @var CheckoutSession| MockObject
5554 */
5655 protected $ eventManagerMock ;
5756
@@ -60,14 +59,17 @@ class MakePersistentQuoteGuestObserverTest extends TestCase
6059 */
6160 protected $ actionMock ;
6261
62+ /**
63+ * @inheritdoc
64+ */
6365 protected function setUp (): void
6466 {
6567 $ this ->actionMock = $ this ->createMock (Index::class);
6668 $ this ->observerMock = $ this ->createMock (Observer::class);
6769 $ this ->sessionHelperMock = $ this ->createMock (Session::class);
6870 $ this ->helperMock = $ this ->createMock (Data::class);
6971 $ this ->customerSessionMock = $ this ->createMock (\Magento \Customer \Model \Session::class);
70- $ this ->quoteManagerMock = $ this ->createMock (QuoteManager ::class);
72+ $ this ->checkoutSession = $ this ->createMock (CheckoutSession ::class);
7173 $ this ->eventManagerMock =
7274 $ this ->getMockBuilder (Event::class)
7375 ->addMethods (['getControllerAction ' ])
@@ -81,7 +83,7 @@ protected function setUp(): void
8183 $ this ->sessionHelperMock ,
8284 $ this ->helperMock ,
8385 $ this ->customerSessionMock ,
84- $ this ->quoteManagerMock
86+ $ this ->checkoutSession
8587 );
8688 }
8789
@@ -94,7 +96,8 @@ public function testExecute()
9496 $ this ->sessionHelperMock ->expects ($ this ->once ())->method ('isPersistent ' )->willReturn (true );
9597 $ this ->customerSessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (false );
9698 $ this ->helperMock ->expects ($ this ->never ())->method ('isShoppingCartPersist ' );
97- $ this ->quoteManagerMock ->expects ($ this ->once ())->method ('setGuest ' )->with (true );
99+ $ this ->checkoutSession ->expects ($ this ->once ())->method ('clearQuote ' )->willReturnSelf ();
100+ $ this ->checkoutSession ->expects ($ this ->once ())->method ('clearStorage ' )->willReturnSelf ();
98101 $ this ->model ->execute ($ this ->observerMock );
99102 }
100103
@@ -107,7 +110,8 @@ public function testExecuteWhenShoppingCartIsPersist()
107110 $ this ->sessionHelperMock ->expects ($ this ->once ())->method ('isPersistent ' )->willReturn (true );
108111 $ this ->customerSessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (true );
109112 $ this ->helperMock ->expects ($ this ->once ())->method ('isShoppingCartPersist ' )->willReturn (true );
110- $ this ->quoteManagerMock ->expects ($ this ->once ())->method ('setGuest ' )->with (true );
113+ $ this ->checkoutSession ->expects ($ this ->once ())->method ('clearQuote ' )->willReturnSelf ();
114+ $ this ->checkoutSession ->expects ($ this ->once ())->method ('clearStorage ' )->willReturnSelf ();
111115 $ this ->model ->execute ($ this ->observerMock );
112116 }
113117
@@ -120,7 +124,8 @@ public function testExecuteWhenShoppingCartIsNotPersist()
120124 $ this ->sessionHelperMock ->expects ($ this ->once ())->method ('isPersistent ' )->willReturn (true );
121125 $ this ->customerSessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (true );
122126 $ this ->helperMock ->expects ($ this ->once ())->method ('isShoppingCartPersist ' )->willReturn (false );
123- $ this ->quoteManagerMock ->expects ($ this ->never ())->method ('setGuest ' );
127+ $ this ->checkoutSession ->expects ($ this ->never ())->method ('clearQuote ' )->willReturnSelf ();
128+ $ this ->checkoutSession ->expects ($ this ->never ())->method ('clearStorage ' )->willReturnSelf ();
124129 $ this ->model ->execute ($ this ->observerMock );
125130 }
126131}
0 commit comments