9
9
use Magento \Framework \ObjectManagerInterface ;
10
10
use Magento \Quote \Model \Quote ;
11
11
use Magento \Quote \Model \QuoteManagement ;
12
+ use Magento \Quote \Model \SubmitQuoteValidator ;
12
13
use Magento \Sales \Api \OrderManagementInterface ;
13
14
use Magento \Sales \Model \Service \OrderService ;
14
15
use Magento \SalesRule \Model \Coupon ;
@@ -158,14 +159,16 @@ public function testSubmitQuoteAndCancelOrder()
158
159
/**
159
160
* Test to decrement coupon usages after exception on order placing
160
161
*
162
+ * @param array $mockObjects
161
163
* @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php
164
+ * @magentoDbIsolation disabled
165
+ * @dataProvider quoteSubmitFailureDataProvider
162
166
*/
163
- public function testSubmitQuoteWithError ( )
167
+ public function testQuoteSubmitFailure ( array $ mockObjects )
164
168
{
165
169
$ customerId = 1 ;
166
170
$ couponCode = 'one_usage ' ;
167
171
$ reservedOrderId = 'test01 ' ;
168
- $ exceptionMessage = 'Some test exception ' ;
169
172
170
173
/** @var Coupon $coupon */
171
174
$ coupon = $ this ->objectManager ->get (Coupon::class);
@@ -174,23 +177,16 @@ public function testSubmitQuoteWithError()
174
177
$ quote = $ this ->objectManager ->get (Quote::class);
175
178
$ quote ->load ($ reservedOrderId , 'reserved_order_id ' );
176
179
177
- /** @var OrderManagementInterface|MockObject $orderManagement */
178
- $ orderManagement = $ this ->createMock (OrderManagementInterface::class);
179
- $ orderManagement ->expects ($ this ->once ())
180
- ->method ('place ' )
181
- ->willThrowException (new \Exception ($ exceptionMessage ));
182
-
183
180
/** @var QuoteManagement $quoteManagement */
184
181
$ quoteManagement = $ this ->objectManager ->create (
185
182
QuoteManagement::class,
186
- [ ' orderManagement ' => $ orderManagement ]
183
+ $ mockObjects
187
184
);
188
185
189
186
try {
190
187
$ quoteManagement ->submit ($ quote );
191
188
} catch (\Exception $ exception ) {
192
- $ this ->assertEquals ($ exceptionMessage , $ exception ->getMessage ());
193
-
189
+ sleep (10 ); // timeout to processing queue
194
190
$ this ->usage ->loadByCustomerCoupon ($ this ->couponUsage , $ customerId , $ coupon ->getId ());
195
191
$ coupon ->loadByCode ($ couponCode );
196
192
self ::assertEquals (
@@ -203,4 +199,31 @@ public function testSubmitQuoteWithError()
203
199
);
204
200
}
205
201
}
202
+
203
+ /**
204
+ * @return array
205
+ */
206
+ public function quoteSubmitFailureDataProvider (): array
207
+ {
208
+ /** @var OrderManagementInterface|MockObject $orderManagement */
209
+ $ orderManagement = $ this ->createMock (OrderManagementInterface::class);
210
+ $ orderManagement ->expects ($ this ->once ())
211
+ ->method ('place ' )
212
+ ->willThrowException (new \Exception ());
213
+
214
+ /** @var OrderManagementInterface|MockObject $orderManagement */
215
+ $ submitQuoteValidator = $ this ->createMock (SubmitQuoteValidator::class);
216
+ $ submitQuoteValidator ->expects ($ this ->once ())
217
+ ->method ('validateQuote ' )
218
+ ->willThrowException (new \Exception ());
219
+
220
+ return [
221
+ 'order placing failure ' => [
222
+ ['orderManagement ' => $ orderManagement ]
223
+ ],
224
+ 'quote validation failure ' => [
225
+ ['submitQuoteValidator ' => $ submitQuoteValidator ]
226
+ ],
227
+ ];
228
+ }
206
229
}
0 commit comments