99use Magento \Framework \ObjectManagerInterface ;
1010use Magento \Quote \Model \Quote ;
1111use Magento \Quote \Model \QuoteManagement ;
12+ use Magento \Quote \Model \SubmitQuoteValidator ;
1213use Magento \Sales \Api \OrderManagementInterface ;
1314use Magento \Sales \Model \Service \OrderService ;
1415use Magento \SalesRule \Model \Coupon ;
@@ -158,14 +159,16 @@ public function testSubmitQuoteAndCancelOrder()
158159 /**
159160 * Test to decrement coupon usages after exception on order placing
160161 *
162+ * @param array $mockObjects
161163 * @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php
164+ * @magentoDbIsolation disabled
165+ * @dataProvider quoteSubmitFailureDataProvider
162166 */
163- public function testSubmitQuoteWithError ( )
167+ public function testQuoteSubmitFailure ( array $ mockObjects )
164168 {
165169 $ customerId = 1 ;
166170 $ couponCode = 'one_usage ' ;
167171 $ reservedOrderId = 'test01 ' ;
168- $ exceptionMessage = 'Some test exception ' ;
169172
170173 /** @var Coupon $coupon */
171174 $ coupon = $ this ->objectManager ->get (Coupon::class);
@@ -174,23 +177,16 @@ public function testSubmitQuoteWithError()
174177 $ quote = $ this ->objectManager ->get (Quote::class);
175178 $ quote ->load ($ reservedOrderId , 'reserved_order_id ' );
176179
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-
183180 /** @var QuoteManagement $quoteManagement */
184181 $ quoteManagement = $ this ->objectManager ->create (
185182 QuoteManagement::class,
186- [ ' orderManagement ' => $ orderManagement ]
183+ $ mockObjects
187184 );
188185
189186 try {
190187 $ quoteManagement ->submit ($ quote );
191188 } catch (\Exception $ exception ) {
192- $ this ->assertEquals ($ exceptionMessage , $ exception ->getMessage ());
193-
189+ sleep (10 ); // timeout to processing queue
194190 $ this ->usage ->loadByCustomerCoupon ($ this ->couponUsage , $ customerId , $ coupon ->getId ());
195191 $ coupon ->loadByCode ($ couponCode );
196192 self ::assertEquals (
@@ -203,4 +199,31 @@ public function testSubmitQuoteWithError()
203199 );
204200 }
205201 }
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+ }
206229}
0 commit comments