1
1
<?php
2
2
/**
3
- *
4
3
* Copyright © Magento, Inc. All rights reserved.
5
4
* See COPYING.txt for license details.
6
5
*/
7
6
declare (strict_types=1 );
8
7
9
8
namespace Magento \Persistent \Test \Unit \Observer ;
10
9
10
+ use Magento \Checkout \Model \Session as CheckoutSession ;
11
11
use Magento \Framework \Event ;
12
12
use Magento \Framework \Event \Observer ;
13
13
use Magento \Persistent \Controller \Index ;
14
14
use Magento \Persistent \Helper \Data ;
15
15
use Magento \Persistent \Helper \Session ;
16
- use Magento \Persistent \Model \QuoteManager ;
17
16
use Magento \Persistent \Observer \MakePersistentQuoteGuestObserver ;
18
17
use PHPUnit \Framework \MockObject \MockObject ;
19
18
use PHPUnit \Framework \TestCase ;
@@ -48,10 +47,10 @@ class MakePersistentQuoteGuestObserverTest extends TestCase
48
47
/**
49
48
* @var MockObject
50
49
*/
51
- protected $ quoteManagerMock ;
50
+ protected $ checkoutSession ;
52
51
53
52
/**
54
- * @var MockObject
53
+ * @var CheckoutSession| MockObject
55
54
*/
56
55
protected $ eventManagerMock ;
57
56
@@ -60,14 +59,17 @@ class MakePersistentQuoteGuestObserverTest extends TestCase
60
59
*/
61
60
protected $ actionMock ;
62
61
62
+ /**
63
+ * @inheritdoc
64
+ */
63
65
protected function setUp (): void
64
66
{
65
67
$ this ->actionMock = $ this ->createMock (Index::class);
66
68
$ this ->observerMock = $ this ->createMock (Observer::class);
67
69
$ this ->sessionHelperMock = $ this ->createMock (Session::class);
68
70
$ this ->helperMock = $ this ->createMock (Data::class);
69
71
$ this ->customerSessionMock = $ this ->createMock (\Magento \Customer \Model \Session::class);
70
- $ this ->quoteManagerMock = $ this ->createMock (QuoteManager ::class);
72
+ $ this ->checkoutSession = $ this ->createMock (CheckoutSession ::class);
71
73
$ this ->eventManagerMock =
72
74
$ this ->getMockBuilder (Event::class)
73
75
->addMethods (['getControllerAction ' ])
@@ -81,7 +83,7 @@ protected function setUp(): void
81
83
$ this ->sessionHelperMock ,
82
84
$ this ->helperMock ,
83
85
$ this ->customerSessionMock ,
84
- $ this ->quoteManagerMock
86
+ $ this ->checkoutSession
85
87
);
86
88
}
87
89
@@ -94,7 +96,8 @@ public function testExecute()
94
96
$ this ->sessionHelperMock ->expects ($ this ->once ())->method ('isPersistent ' )->willReturn (true );
95
97
$ this ->customerSessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (false );
96
98
$ 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 ();
98
101
$ this ->model ->execute ($ this ->observerMock );
99
102
}
100
103
@@ -107,7 +110,8 @@ public function testExecuteWhenShoppingCartIsPersist()
107
110
$ this ->sessionHelperMock ->expects ($ this ->once ())->method ('isPersistent ' )->willReturn (true );
108
111
$ this ->customerSessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (true );
109
112
$ 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 ();
111
115
$ this ->model ->execute ($ this ->observerMock );
112
116
}
113
117
@@ -120,7 +124,8 @@ public function testExecuteWhenShoppingCartIsNotPersist()
120
124
$ this ->sessionHelperMock ->expects ($ this ->once ())->method ('isPersistent ' )->willReturn (true );
121
125
$ this ->customerSessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (true );
122
126
$ 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 ();
124
129
$ this ->model ->execute ($ this ->observerMock );
125
130
}
126
131
}
0 commit comments