11
11
12
12
use Magento \Framework \Api \SortOrder ;
13
13
use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
14
+ use Magento \Quote \Model \QuoteRepository \LoadHandler ;
14
15
15
16
class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
16
17
{
@@ -54,6 +55,11 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
54
55
*/
55
56
private $ extensionAttributesJoinProcessorMock ;
56
57
58
+ /**
59
+ * @var LoadHandler|\PHPUnit_Framework_MockObject_MockObject
60
+ */
61
+ private $ loadHandlerMock ;
62
+
57
63
protected function setUp ()
58
64
{
59
65
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
@@ -107,6 +113,12 @@ protected function setUp()
107
113
'extensionAttributesJoinProcessor ' => $ this ->extensionAttributesJoinProcessorMock
108
114
]
109
115
);
116
+
117
+ $ this ->loadHandlerMock = $ this ->getMock (LoadHandler::class, [], [], '' , false );
118
+ $ reflection = new \ReflectionClass (get_class ($ this ->model ));
119
+ $ reflectionProperty = $ reflection ->getProperty ('loadHandler ' );
120
+ $ reflectionProperty ->setAccessible (true );
121
+ $ reflectionProperty ->setValue ($ this ->model , $ this ->loadHandlerMock );
110
122
}
111
123
112
124
/**
@@ -132,23 +144,74 @@ public function testGetWithExceptionById()
132
144
133
145
public function testGet ()
134
146
{
135
- $ this ->markTestSkipped ('MAGETWO-48531 ' );
136
147
$ cartId = 15 ;
137
148
138
- $ this ->quoteFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteMock );
139
- $ this ->storeManagerMock ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ this ->storeMock );
140
- $ this ->storeMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
141
- $ this ->quoteMock ->expects ($ this ->never ())->method ('setSharedStoreIds ' );
142
- $ this ->quoteMock ->expects ($ this ->once ())
149
+ $ this ->quoteFactoryMock ->expects (static ::once ())
150
+ ->method ('create ' )
151
+ ->willReturn ($ this ->quoteMock );
152
+ $ this ->storeManagerMock ->expects (static ::once ())
153
+ ->method ('getStore ' )
154
+ ->willReturn ($ this ->storeMock );
155
+ $ this ->storeMock ->expects (static ::once ())
156
+ ->method ('getId ' )
157
+ ->willReturn (1 );
158
+ $ this ->quoteMock ->expects (static ::never ())
159
+ ->method ('setSharedStoreIds ' );
160
+ $ this ->quoteMock ->expects (static ::once ())
143
161
->method ('load ' )
144
162
->with ($ cartId )
145
163
->willReturn ($ this ->storeMock );
146
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ cartId );
164
+ $ this ->quoteMock ->expects (static ::once ())
165
+ ->method ('getId ' )
166
+ ->willReturn ($ cartId );
167
+ $ this ->quoteMock ->expects (static ::never ())
168
+ ->method ('getCustomerId ' );
169
+ $ this ->loadHandlerMock ->expects (static ::once ())
170
+ ->method ('load ' )
171
+ ->with ($ this ->quoteMock );
147
172
148
173
$ this ->assertEquals ($ this ->quoteMock , $ this ->model ->get ($ cartId ));
149
174
$ this ->assertEquals ($ this ->quoteMock , $ this ->model ->get ($ cartId ));
150
175
}
151
176
177
+ public function testGetForCustomerAfterGet ()
178
+ {
179
+ $ cartId = 15 ;
180
+ $ customerId = 23 ;
181
+
182
+ $ this ->quoteFactoryMock ->expects (static ::exactly (2 ))
183
+ ->method ('create ' )
184
+ ->willReturn ($ this ->quoteMock );
185
+ $ this ->storeManagerMock ->expects (static ::exactly (2 ))
186
+ ->method ('getStore ' )
187
+ ->willReturn ($ this ->storeMock );
188
+ $ this ->storeMock ->expects (static ::exactly (2 ))
189
+ ->method ('getId ' )
190
+ ->willReturn (1 );
191
+ $ this ->quoteMock ->expects (static ::never ())
192
+ ->method ('setSharedStoreIds ' );
193
+ $ this ->quoteMock ->expects (static ::once ())
194
+ ->method ('load ' )
195
+ ->with ($ cartId )
196
+ ->willReturn ($ this ->storeMock );
197
+ $ this ->quoteMock ->expects (static ::once ())
198
+ ->method ('loadByCustomer ' )
199
+ ->with ($ customerId )
200
+ ->willReturn ($ this ->storeMock );
201
+ $ this ->quoteMock ->expects (static ::exactly (3 ))
202
+ ->method ('getId ' )
203
+ ->willReturn ($ cartId );
204
+ $ this ->quoteMock ->expects (static ::any ())
205
+ ->method ('getCustomerId ' )
206
+ ->willReturn ($ customerId );
207
+ $ this ->loadHandlerMock ->expects (static ::exactly (2 ))
208
+ ->method ('load ' )
209
+ ->with ($ this ->quoteMock );
210
+
211
+ $ this ->assertEquals ($ this ->quoteMock , $ this ->model ->get ($ cartId ));
212
+ $ this ->assertEquals ($ this ->quoteMock , $ this ->model ->getForCustomer ($ customerId ));
213
+ }
214
+
152
215
public function testGetWithSharedStoreIds ()
153
216
{
154
217
$ this ->markTestSkipped ('MAGETWO-48531 ' );
@@ -174,19 +237,31 @@ public function testGetWithSharedStoreIds()
174
237
175
238
public function testGetForCustomer ()
176
239
{
177
- $ this ->markTestSkipped ('MAGETWO-48531 ' );
178
240
$ cartId = 17 ;
179
241
$ customerId = 23 ;
180
242
181
- $ this ->quoteFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteMock );
182
- $ this ->storeManagerMock ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ this ->storeMock );
183
- $ this ->storeMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
184
- $ this ->quoteMock ->expects ($ this ->never ())->method ('setSharedStoreIds ' );
185
- $ this ->quoteMock ->expects ($ this ->once ())
243
+ $ this ->quoteFactoryMock ->expects (static ::once ())
244
+ ->method ('create ' )
245
+ ->willReturn ($ this ->quoteMock );
246
+ $ this ->storeManagerMock ->expects (static ::once ())
247
+ ->method ('getStore ' )
248
+ ->willReturn ($ this ->storeMock );
249
+ $ this ->storeMock ->expects (static ::once ())
250
+ ->method ('getId ' )
251
+ ->willReturn (1 );
252
+ $ this ->quoteMock ->expects (static ::never ())
253
+ ->method ('setSharedStoreIds ' );
254
+ $ this ->quoteMock ->expects (static ::once ())
186
255
->method ('loadByCustomer ' )
187
256
->with ($ customerId )
188
257
->willReturn ($ this ->storeMock );
189
- $ this ->quoteMock ->expects ($ this ->exactly (2 ))->method ('getId ' )->willReturn ($ cartId );
258
+ $ this ->quoteMock ->expects (static ::exactly (2 ))
259
+ ->method ('getId ' )
260
+ ->willReturn ($ cartId );
261
+
262
+ $ this ->loadHandlerMock ->expects (static ::once ())
263
+ ->method ('load ' )
264
+ ->with ($ this ->quoteMock );
190
265
191
266
$ this ->assertEquals ($ this ->quoteMock , $ this ->model ->getForCustomer ($ customerId ));
192
267
$ this ->assertEquals ($ this ->quoteMock , $ this ->model ->getForCustomer ($ customerId ));
0 commit comments