@@ -126,6 +126,16 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
126
126
*/
127
127
protected $ quoteFactoryMock ;
128
128
129
+ /**
130
+ * @var \PHPUnit_Framework_MockObject_MockObject
131
+ */
132
+ private $ quoteIdFactoryMock ;
133
+
134
+ /**
135
+ * @var \PHPUnit_Framework_MockObject_MockObject
136
+ */
137
+ private $ quoteIdMock ;
138
+
129
139
/**
130
140
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
131
141
*/
@@ -238,7 +248,6 @@ protected function setUp()
238
248
);
239
249
240
250
$ this ->quoteFactoryMock = $ this ->getMock ('\Magento\Quote\Model\QuoteFactory ' , ['create ' ], [], '' , false );
241
-
242
251
$ this ->model = $ objectManager ->getObject (
243
252
'\Magento\Quote\Model\QuoteManagement ' ,
244
253
[
@@ -264,6 +273,12 @@ protected function setUp()
264
273
'quoteFactory ' => $ this ->quoteFactoryMock
265
274
]
266
275
);
276
+
277
+ // Set the new dependency
278
+ $ this ->quoteIdMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMask ' , [], [], '' , false );
279
+ $ quoteIdFactoryMock = $ this ->getMock (\Magento \Quote \Model \QuoteIdMaskFactory::class, ['create ' ], [], '' , false );
280
+ $ this ->setPropertyValue ($ this ->model , 'quoteIdMaskFactory ' , $ quoteIdFactoryMock );
281
+
267
282
}
268
283
269
284
public function testCreateEmptyCartAnonymous ()
@@ -508,6 +523,10 @@ public function testAssignCustomer()
508
523
$ customerId = 455 ;
509
524
$ storeId = 5 ;
510
525
526
+ $ this ->getPropertyValue ($ this ->model , 'quoteIdMaskFactory ' )->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMock );
527
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('load ' )->with ($ cartId , 'quote_id ' )->willReturnSelf ();
528
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (10 );
529
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('delete ' );
511
530
$ quoteMock = $ this ->getMock (
512
531
'\Magento\Quote\Model\Quote ' ,
513
532
['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' ],
@@ -979,4 +998,37 @@ public function testGetCartForCustomer()
979
998
->willReturn ($ cartMock );
980
999
$ this ->assertEquals ($ cartMock , $ this ->model ->getCartForCustomer ($ customerId ));
981
1000
}
1001
+
1002
+ /**
1003
+ * Get any object property value.
1004
+ *
1005
+ * @param $object
1006
+ * @param $property
1007
+ * @return mixed
1008
+ */
1009
+ protected function getPropertyValue ($ object , $ property )
1010
+ {
1011
+ $ reflection = new \ReflectionClass (get_class ($ object ));
1012
+ $ reflectionProperty = $ reflection ->getProperty ($ property );
1013
+ $ reflectionProperty ->setAccessible (true );
1014
+
1015
+ return $ reflectionProperty ->getValue ($ object );
1016
+ }
1017
+
1018
+ /**
1019
+ * Set object property value.
1020
+ *
1021
+ * @param $object
1022
+ * @param $property
1023
+ * @param $value
1024
+ */
1025
+ protected function setPropertyValue (&$ object , $ property , $ value )
1026
+ {
1027
+ $ reflection = new \ReflectionClass (get_class ($ object ));
1028
+ $ reflectionProperty = $ reflection ->getProperty ($ property );
1029
+ $ reflectionProperty ->setAccessible (true );
1030
+ $ reflectionProperty ->setValue ($ object , $ value );
1031
+
1032
+ return $ object ;
1033
+ }
982
1034
}
0 commit comments