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