9
9
namespace Magento \Persistent \Test \Unit \Model ;
10
10
11
11
use Magento \Checkout \Model \Session ;
12
+ use Magento \Customer \Api \Data \CustomerInterface ;
13
+ use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
12
14
use Magento \Customer \Model \GroupManagement ;
13
15
use Magento \Eav \Model \Entity \Collection \AbstractCollection ;
14
16
use Magento \Persistent \Helper \Data ;
@@ -78,6 +80,11 @@ class QuoteManagerTest extends TestCase
78
80
*/
79
81
private $ shippingAssignmentProcessor ;
80
82
83
+ /**
84
+ * @var CustomerInterfaceFactory|MockObject
85
+ */
86
+ private $ customerDataFactory ;
87
+
81
88
protected function setUp (): void
82
89
{
83
90
$ this ->persistentSessionMock = $ this ->createMock (\Magento \Persistent \Helper \Session::class);
@@ -124,21 +131,24 @@ protected function setUp(): void
124
131
'getItemsQty ' ,
125
132
'getExtensionAttributes ' ,
126
133
'setExtensionAttributes ' ,
127
- '__wakeup '
134
+ '__wakeup ' ,
135
+ 'setCustomer '
128
136
])
129
137
->disableOriginalConstructor ()
130
138
->getMock ();
131
139
132
140
$ this ->cartExtensionFactory = $ this ->createPartialMock (CartExtensionFactory::class, ['create ' ]);
133
141
$ this ->shippingAssignmentProcessor = $ this ->createPartialMock (ShippingAssignmentProcessor::class, ['create ' ]);
142
+ $ this ->customerDataFactory = $ this ->createMock (CustomerInterfaceFactory::class);
134
143
135
144
$ this ->model = new QuoteManager (
136
145
$ this ->persistentSessionMock ,
137
146
$ this ->persistentDataMock ,
138
147
$ this ->checkoutSessionMock ,
139
148
$ this ->quoteRepositoryMock ,
140
149
$ this ->cartExtensionFactory ,
141
- $ this ->shippingAssignmentProcessor
150
+ $ this ->shippingAssignmentProcessor ,
151
+ $ this ->customerDataFactory
142
152
);
143
153
}
144
154
@@ -189,6 +199,7 @@ public function testSetGuestWhenShoppingCartAndQuoteAreNotPersistent()
189
199
190
200
public function testSetGuest ()
191
201
{
202
+ $ customerId = 22 ;
192
203
$ this ->checkoutSessionMock ->expects ($ this ->once ())
193
204
->method ('getQuote ' )->willReturn ($ this ->quoteMock );
194
205
$ this ->quoteMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (11 );
@@ -220,6 +231,7 @@ public function testSetGuest()
220
231
->method ('getShippingAddress ' )->willReturn ($ quoteAddressMock );
221
232
$ this ->quoteMock ->expects ($ this ->once ())
222
233
->method ('getBillingAddress ' )->willReturn ($ quoteAddressMock );
234
+ $ this ->quoteMock ->method ('getCustomerId ' )->willReturn ($ customerId );
223
235
$ this ->quoteMock ->expects ($ this ->once ())->method ('collectTotals ' )->willReturn ($ this ->quoteMock );
224
236
$ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ this ->quoteMock );
225
237
$ this ->persistentSessionMock ->expects ($ this ->once ())
@@ -229,7 +241,6 @@ public function testSetGuest()
229
241
$ this ->quoteMock ->expects ($ this ->once ())->method ('isVirtual ' )->willReturn (false );
230
242
$ this ->quoteMock ->expects ($ this ->once ())->method ('getItemsQty ' )->willReturn (1 );
231
243
$ extensionAttributes = $ this ->getMockBuilder (CartExtensionInterface::class)
232
- ->addMethods (['getShippingAssignments ' , 'setShippingAssignments ' ])
233
244
->getMockForAbstractClass ();
234
245
$ shippingAssignment = $ this ->createMock (ShippingAssignmentInterface::class);
235
246
$ extensionAttributes ->expects ($ this ->once ())
@@ -248,6 +259,11 @@ public function testSetGuest()
248
259
$ this ->quoteMock ->expects ($ this ->once ())
249
260
->method ('setExtensionAttributes ' )
250
261
->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 );
251
267
$ this ->model ->setGuest (false );
252
268
}
253
269
0 commit comments