@@ -92,6 +92,11 @@ class QuoteTest extends \PHPUnit_Framework_TestCase
92
92
*/
93
93
protected $ quoteFactoryMock ;
94
94
95
+ /**
96
+ * @var \PHPUnit_Framework_MockObject_MockObject
97
+ */
98
+ protected $ cartManagementMock ;
99
+
95
100
/**
96
101
* Set up
97
102
*
@@ -197,9 +202,16 @@ protected function setUp()
197
202
);
198
203
199
204
$ this ->quoteFactoryMock = $ this ->getMock ('\Magento\Quote\Model\QuoteFactory ' , ['create ' ], [], '' , false );
205
+ $ this ->cartManagementMock = $ this ->getMock (
206
+ \Magento \Quote \Api \CartManagementInterface::class,
207
+ [],
208
+ [],
209
+ '' ,
210
+ false
211
+ );
200
212
201
213
$ this ->quote = $ this ->getMock (
202
- ' Magento\Backend\Model\Session\Quote ' ,
214
+ \ Magento \Backend \Model \Session \Quote::class ,
203
215
['getStoreId ' , 'getQuoteId ' , 'setQuoteId ' , 'hasCustomerId ' , 'getCustomerId ' ],
204
216
[
205
217
'request ' => $ this ->requestMock ,
@@ -217,10 +229,12 @@ protected function setUp()
217
229
'storeManager ' => $ this ->storeManagerMock ,
218
230
'groupManagement ' => $ this ->groupManagementMock ,
219
231
'quoteFactory ' => $ this ->quoteFactoryMock
220
- ],
221
- '' ,
222
- true
232
+ ]
223
233
);
234
+
235
+ $ this ->prepareObjectManager ([
236
+ [\Magento \Quote \Api \CartManagementInterface::class, $ this ->cartManagementMock ]
237
+ ]);
224
238
}
225
239
226
240
/**
@@ -235,6 +249,8 @@ public function testGetQuoteWithoutQuoteId()
235
249
$ customerId = 66 ;
236
250
$ customerGroupId = 77 ;
237
251
252
+ $ this ->cartManagementMock ->expects ($ this ->once ())->method ('createEmptyCart ' )->willReturn ($ quoteId );
253
+
238
254
$ this ->quote ->expects ($ this ->any ())
239
255
->method ('getQuoteId ' )
240
256
->will ($ this ->returnValue (null ));
@@ -271,7 +287,6 @@ public function testGetQuoteWithoutQuoteId()
271
287
'setStoreId ' ,
272
288
'setCustomerGroupId ' ,
273
289
'setIsActive ' ,
274
- 'getId ' ,
275
290
'assignCustomer ' ,
276
291
'setIgnoreOldQty ' ,
277
292
'setIsSuperMode ' ,
@@ -281,9 +296,7 @@ public function testGetQuoteWithoutQuoteId()
281
296
'' ,
282
297
false
283
298
);
284
- $ quoteMock ->expects ($ this ->once ())
285
- ->method ('setStoreId ' )
286
- ->with ($ storeId );
299
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ quoteMock );
287
300
$ quoteMock ->expects ($ this ->once ())
288
301
->method ('setCustomerGroupId ' )
289
302
->with ($ customerGroupId )
@@ -292,9 +305,6 @@ public function testGetQuoteWithoutQuoteId()
292
305
->method ('setIsActive ' )
293
306
->with (false )
294
307
->will ($ this ->returnSelf ());
295
- $ quoteMock ->expects ($ this ->once ())
296
- ->method ('getId ' )
297
- ->will ($ this ->returnValue ($ quoteId ));
298
308
$ quoteMock ->expects ($ this ->once ())
299
309
->method ('assignCustomer ' )
300
310
->with ($ dataCustomerMock );
@@ -305,13 +315,6 @@ public function testGetQuoteWithoutQuoteId()
305
315
->method ('setIsSuperMode ' )
306
316
->with (true );
307
317
308
- $ this ->quoteFactoryMock ->expects ($ this ->once ())
309
- ->method ('create ' )
310
- ->will ($ this ->returnValue ($ quoteMock ));
311
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
312
- ->method ('save ' )
313
- ->with ($ quoteMock );
314
-
315
318
$ this ->assertEquals ($ quoteMock , $ this ->quote ->getQuote ());
316
319
}
317
320
@@ -380,9 +383,6 @@ public function testGetQuoteWithQuoteId($customerId, $quoteCustomerId, $expected
380
383
->method ('getCustomerId ' )
381
384
->will ($ this ->returnValue ($ quoteCustomerId ));
382
385
383
- $ this ->quoteFactoryMock ->expects ($ this ->once ())
384
- ->method ('create ' )
385
- ->will ($ this ->returnValue ($ quoteMock ));
386
386
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
387
387
->method ('get ' )
388
388
->with ($ quoteId )
@@ -401,4 +401,19 @@ public function getQuoteDataProvider()
401
401
'customer ids same ' => [66 , 66 , 'never ' ],
402
402
];
403
403
}
404
+
405
+ /**
406
+ * @param array $map
407
+ * @deprecated
408
+ */
409
+ private function prepareObjectManager ($ map )
410
+ {
411
+ $ objectManagerMock = $ this ->getMock ('Magento\Framework\ObjectManagerInterface ' );
412
+ $ objectManagerMock ->expects ($ this ->any ())->method ('getInstance ' )->willReturnSelf ();
413
+ $ objectManagerMock ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValueMap ($ map ));
414
+ $ reflectionClass = new \ReflectionClass ('Magento\Framework\App\ObjectManager ' );
415
+ $ reflectionProperty = $ reflectionClass ->getProperty ('_instance ' );
416
+ $ reflectionProperty ->setAccessible (true );
417
+ $ reflectionProperty ->setValue ($ objectManagerMock );
418
+ }
404
419
}
0 commit comments